collections

Sorting Object with Comparator gives Null Pointer

旧街凉风 提交于 2020-01-14 12:46:26
问题 I am trying sort the ArrayList with 3 Card in it. I am doing this with a Comparator. (Is this overkill)? Card.getRank() returns an integer between 2 and 14. I have absolutely no idea where I am going wrong. I have done this successfully before, and compared with my other code, and it seems the same. I would greatly appreciate if someone could spread some light on this! public int getHand(Card c1, Card c2, Card c3) { ArrayList<Card> hand = new ArrayList<Card>(); hand.add(c1); hand.add(c2);

How to Get Values from List of HashMap?

岁酱吖の 提交于 2020-01-14 11:58:28
问题 I have a List of HashMap 's which has key of type Integer and value of type Long . List<HashMap<Integer, Long>> ListofHash = new ArrayList<HashMap<Integer, Long>>(); for (int i = 0; i < 10; i++) { HashMap<Integer, Long> mMap = new HashMap<Integer, Long>(); mMap.put(Integer.valueOf(i), Long.valueOf(100000000000L+i)); ListofHash.add(mMap); } Now, how do I retrieve the key and value from the list of HashMap ? If using Collection class is the solution, please enlight me. Update 1: Actually i am

DateTime as key in a SortedDictionary<K, V>

旧时模样 提交于 2020-01-14 09:39:57
问题 Can I safely use DateTime as a key in a SortedDictionary<K, V> without implementing my own IComparer ? I've tried it and sort order is maintained and importantly for my purpose the .ContainsKey<T> method works as expected. But I just want to double check before committing myself down this road. 回答1: you will not need a new IComparer. your default IComparer will use the GetHashCode() from your value object and compare/sort with that. Since the DateTime type implements the GetHashCode()

Is throwing ConcurrentModificationException system dependent

前提是你 提交于 2020-01-14 08:00:31
问题 I am working on a piece of code with Iterator and getting a ConcurrentModificationException at the line a when I run the program from my IDE on windows-- LinkedList ll =new LinkedList(); . . . . . . Iterator iter = ll.iterator(); int i=0; while (iter.hasNext()) { // GrammarSection agrammarSection = (GrammarSection) iter.next(); //a String s1 = (String) iter.next(); ll.remove(i); i++; } This is expected because Im modifying the list while I'm iterating so the fail-fast iterator throws a

RoR - collection_select from array

ⅰ亾dé卋堺 提交于 2020-01-14 07:23:08
问题 I've a little array: @dates= ['2013-11-01', '2013-11-02', '2013-11-03', '2013-11-04', '2013-11-05'] how can i put these array in an collection_select in the view? I tried: ... <%= f.collection_select :day, Day.order(:date), :id, @dates, include_blank: false %> ... 回答1: Assuming that you mean to use the date strings for both the value (returned from form) and text (displayed in drop-down) of the select then = f.collection_select :day, @dates, :to_s, :to_s, include_blank: false This will pass

How can you reverse traverse through a C# collection?

≯℡__Kan透↙ 提交于 2020-01-14 07:13:20
问题 Is it possible to have a foreach statement that will traverse through a Collections object in reverse order? If not a foreach statement, is there another way? 回答1: You can use a normal for loop backwards, like this: for (int i = collection.Count - 1; i >= 0 ; i--) { var current = collection[i]; //Do things } You can also use LINQ: foreach(var current in collection.Reverse()) { //Do things } However, the normal for loop will probably be a little bit faster. 回答2: You could just call Reverse()

To store unique element in a collection with natural order

我怕爱的太早我们不能终老 提交于 2020-01-14 06:18:37
问题 While I was solving a Java test I came up with the following question: You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability? A. java.util.Map B. java.util.Set C. java.util.List D. java.util.Collection I have no idea what is the right case here? We can store the same element in any of these collections unless in a Set , but the Set doesn't provide the natural order.

meteor collection fetching too slow

烈酒焚心 提交于 2020-01-14 03:28:07
问题 I have an app that subscribes to 4 collections (the collections are very small 1 to 20 records each). But the amount of time it takes to load these collections is huge. One of them is just 13 records, and it takes several seconds to load its template. Is it normal? (I'm still testing on meteor servers) this is a sample of the code : Meteor.subscribe('trackedUser', function() { console.log('finished fetching trackedUser'); Template.users.rendered = function() { /*handlign of the template*/

Android ignore case when sorting list

杀马特。学长 韩版系。学妹 提交于 2020-01-13 19:14:08
问题 I have a List named path I'm currently sorting my strings with the following code java.util.Collections.sort(path); That is working fine it sorts my list however it treats the cases of the first letter differently that is it sorts the list with upper-case letters and then sorts the list with lower-case letters after so if I had the following cat dog Bird Zebra it would sort it like Bird Zebra dog cat so how do I ignore case so that dog and cat would come before Zebra but after Bird? Thank you

How to detect a collision in sprite kit?

好久不见. 提交于 2020-01-13 18:01:46
问题 I am making a game in Sprite Kit and I have struggles with the collision detection between SpriteNodes, I've set a sprite node called sprite and a sprite node called platform. I want the sprite to stop falling when collided with the platform. This is what I have: SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"bal.png"]; sprite.position = CGPointMake(self.frame.size.width/4 + arc4random() % ((int)self.frame.size.width/2), (self.frame.size.height/2 + arc4random() % ((int)self