collections

Big-O summary for Java Collections Framework implementations? [closed]

断了今生、忘了曾经 提交于 2019-12-17 00:22:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I may be teaching a "Java crash-course" soon. While it is probably safe to assume that the audience members will know Big-O notation, it is probably not safe to assume that they will know what the order of the various operations on various collection implementations is. I could take time to generate a summary

Is it better to return null or empty collection?

蓝咒 提交于 2019-12-16 19:53:10
问题 That's kind of a general question (but I'm using C#), what's the best way (best practice), do you return null or empty collection for a method that has a collection as a return type ? 回答1: Empty collection. Always. This sucks: if(myInstance.CollectionProperty != null) { foreach(var item in myInstance.CollectionProperty) /* arrgh */ } It is considered a best practice to NEVER return null when returning a collection or enumerable. ALWAYS return an empty enumerable/collection. It prevents the

Is it better to return null or empty collection?

送分小仙女□ 提交于 2019-12-16 19:52:43
问题 That's kind of a general question (but I'm using C#), what's the best way (best practice), do you return null or empty collection for a method that has a collection as a return type ? 回答1: Empty collection. Always. This sucks: if(myInstance.CollectionProperty != null) { foreach(var item in myInstance.CollectionProperty) /* arrgh */ } It is considered a best practice to NEVER return null when returning a collection or enumerable. ALWAYS return an empty enumerable/collection. It prevents the

Querying Typescript array collection based on key

人盡茶涼 提交于 2019-12-14 04:28:06
问题 I am new to Typescript. I have an Array of type in typescript.Basically containing the collection elements as "ID": "669a8156-528c-43ba-8ed0-d07874534d1c", "Name": "Temple", "DeviceCount": "0", "SiteCount": "0" "ID": "5965ee85-2300-4c95-8743-b626f744082f", "Name": "Building", "DeviceCount": "2", "SiteCount": "3" ..so on How do I query the Name property from the collection if I have the ID i.e., something similar to LINQ type of expression var result = array.Where(item => item.ID == ID); 回答1:

Any utility method to sort java.util.List containing POJOs of the kind of apache-* libraries

点点圈 提交于 2019-12-14 04:26:25
问题 Is there any kind of utility method to sort Lists like the following one: POJO pojo1 = new POJO(); pojo1.setFoo("abc"); POJO pojo2 = new POJO(); pojo2.setFoo("abc"); List theList = new ArrayList<POJO>(); theList.add(pojo1); theList.add(pojo2); SortUtils.sort(theList, "foo", SortType.ALPHABETICAL, SortDirection.ASC) EDIT: Thanks for your answers but I know that you can make the POJO implement Comparable or use Collections.sort(list, Comparator) but creating an anonymous class looks like

How to load bootstrapped models of backbone in Django

廉价感情. 提交于 2019-12-14 03:51:41
问题 when backbone app was loaded(for my app it means the page loaded),I need the initial collection data, and backbone docs says: <script> var accounts = new Backbone.Collection; accounts.reset(<%= @accounts.to_json %>); var projects = new Backbone.Collection; projects.reset(<%= @projects.to_json(:collaborators => true) %>); </script> I don't understand this. Dose it mean I should render the page with the initial data like {{collection_initial_data}} I am using django on backends, so how do I

grouping List of Objects and counting using Java collection

半城伤御伤魂 提交于 2019-12-14 03:49:29
问题 Which Java Collection class is better to group the list of objects? I have a list of messages from users like below: aaa hi bbb hello ccc Gm aaa Can? CCC yes ddd No From this list of message object I want to count and display aaa(2)+bbb(1)+ccc(2)+ddd(1) . Any code help? 回答1: Putting the pieces together from a couple of the other answers, adapting to your code from the other question and fixing a few trivial errors: // as you want a sorted list of keys, you should use a TreeMap Map<String,

Sort a list from Arrays.asList() changes also the origin array?

偶尔善良 提交于 2019-12-14 03:47:23
问题 I noticed a strange behavior (for me) when sorting a list retrieved with Arrays.asList() . It seems that after Collections.sort( list ) , the origin array is also sorted ! How is it possible ? List<Rate> rates = Arrays.asList( arrayRates ); Collections.sort( rates, new RateEffectiveDateComparator() ); /* after that the rates list AND arrayRates array are sorted in the same way */ 回答1: From the documentation of Arrays.asList(): Returns a fixed-size list backed by the specified array. (Changes

What's the best way to make this Java program? [closed]

拜拜、爱过 提交于 2019-12-14 03:32:38
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . This the description of the program brief: Produce a software that keeps track of courses taught by lecturers at College. For each

Real time sorted by value, auto-discarding, bounded collection ?

蹲街弑〆低调 提交于 2019-12-14 03:26:45
问题 I spent some time to try to make a collection that: 1) is sorted by value (not by key) 2) is sorted each time an element is added or modified 3) is fixed size and discard automatically smallest/biggest element depending of the sort way 4) is safe thread So 3) and 4) I think it is quite ok. For 1) and 2) it was a bit more tricky. I spent quite a long time on this thread, experimenting the different sample, but one big issue is that the collection are sorted only once when object are inserted.