collections

Difference between a deprecated and a legacy API?

我只是一个虾纸丫 提交于 2019-12-17 07:17:21
问题 I was studying the legacy API's in the Java's Collection Framework and I learnt that classes such as Vector and HashTable have been superseded by ArrayList and HashMap . However still they are NOT deprecated, and deemed as legacy when essentially, deprecation is applied to software features that are superseded and should be avoided, so, I am not sure when is a API deemed legacy and when it is deprecated. 回答1: From the official Sun glossary: deprecation : Refers to a class, interface,

builder for HashMap

。_饼干妹妹 提交于 2019-12-17 07:15:48
问题 Guava provides us with great factory methods for Java types, such as Maps.newHashMap() . But are there also builders for java Maps? HashMap<String,Integer> m = Maps.BuildHashMap. put("a",1). put("b",2). build(); 回答1: Since Java 9 Map interface contains: Map.of(k1,v1, k2,v2, ..) Map.ofEntries(Map.entry(k1,v1), Map.entry(k2,v2), ..) . Limitations of those factory methods are that they: can't hold null s as keys and/or values (if you need to store nulls take a look at other answers) produce

Thread safe collections in .NET

北战南征 提交于 2019-12-17 07:13:06
问题 What is the standard nowadays when one needs a thread safe collection (e.g. Set). Do I synchronize it myself, or is there an inherently thread safe collection? 回答1: The .NET 4.0 Framework introduces several thread-safe collections in the System.Collections.Concurrent Namespace: ConcurrentBag<T> Represents a thread-safe, unordered collection of objects. ConcurrentDictionary<TKey, TValue> Represents a thread-safe collection of key-value pairs that can be accessed by multiple threads

How Iterator's remove method actually remove an object

十年热恋 提交于 2019-12-17 07:12:56
问题 We all know that the safest "and probably only safe" way of removing an object from a collection while iterating it, is by first retrieving the Iterator , perform a loop and remove when needed; Iterator iter=Collection.iterator(); while(iter.hasNext()){ Object o=iter.next() if(o.equals(what i'm looking for)){ iter.remove(); } } What I would like to understand, and unfortunately haven't found a deep technical explanation about, is how this removal is performed, If: for(Object o:myCollection()

How Iterator's remove method actually remove an object

荒凉一梦 提交于 2019-12-17 07:12:30
问题 We all know that the safest "and probably only safe" way of removing an object from a collection while iterating it, is by first retrieving the Iterator , perform a loop and remove when needed; Iterator iter=Collection.iterator(); while(iter.hasNext()){ Object o=iter.next() if(o.equals(what i'm looking for)){ iter.remove(); } } What I would like to understand, and unfortunately haven't found a deep technical explanation about, is how this removal is performed, If: for(Object o:myCollection()

Thread safe collections in .NET

╄→гoц情女王★ 提交于 2019-12-17 07:12:18
问题 What is the standard nowadays when one needs a thread safe collection (e.g. Set). Do I synchronize it myself, or is there an inherently thread safe collection? 回答1: The .NET 4.0 Framework introduces several thread-safe collections in the System.Collections.Concurrent Namespace: ConcurrentBag<T> Represents a thread-safe, unordered collection of objects. ConcurrentDictionary<TKey, TValue> Represents a thread-safe collection of key-value pairs that can be accessed by multiple threads

How to get a reversed list view on a list in Java?

风流意气都作罢 提交于 2019-12-17 07:09:12
问题 I want to have a reversed list view on a list (in a similar way than List#sublist provides a sublist view on a list). Is there some function which provides this functionality? I don't want to make any sort of copy of the list nor modify the list. It would be enough if I could get at least a reverse iterator on a list in this case though. Also, I know how to implement this myself. I'm just asking if Java already provides something like this. Demo implementation: static <T> Iterable<T>

Rule of thumb for choosing an implementation of a Java Collection?

拜拜、爱过 提交于 2019-12-17 07:01:21
问题 Anyone have a good rule of thumb for choosing between different implementations of Java Collection interfaces like List, Map, or Set? For example, generally why or in what cases would I prefer to use a Vector or an ArrayList, a Hashtable or a HashMap? 回答1: I've always made those decisions on a case by case basis, depending on the use case, such as: Do I need the ordering to remain? Will I have null key/values? Dups? Will it be accessed by multiple threads Do I need a key/value pair Will I

Rule of thumb for choosing an implementation of a Java Collection?

ぐ巨炮叔叔 提交于 2019-12-17 07:01:05
问题 Anyone have a good rule of thumb for choosing between different implementations of Java Collection interfaces like List, Map, or Set? For example, generally why or in what cases would I prefer to use a Vector or an ArrayList, a Hashtable or a HashMap? 回答1: I've always made those decisions on a case by case basis, depending on the use case, such as: Do I need the ordering to remain? Will I have null key/values? Dups? Will it be accessed by multiple threads Do I need a key/value pair Will I

Displaying loader while meteor collection loads

独自空忆成欢 提交于 2019-12-17 06:35:41
问题 I have a template, task_list , that looks like this: {{#each tasks}} {{> task}} {{/each}} Template.task_list.tasks returns a collection and in the ui, it seems to take a bit of time to load. While the collection is loading, I'd like to show a loading indicator. Any ideas on how I might be able to do that? BTW, I did try the templates' rendered event on task_list template, however it gets fired before the list is actually loaded. I also tried using rendered on the task template but it seems to