[Solved] How to make ArrayList of hashset in java? [closed]

Just make an ArrayList of HashSets : ArrayList<HashSet<Integer>> list = new ArrayList<HashSet<Integer>>(); Then create HashSets, fill them, and put them in your ArrayList normally. HashSet<Integer> set = new HashSet<Integer>(); set.add(1); set.add(whateverIntValue); list.add(set); You can then get the nth HashSet of your list using list.get(n). solved How to make ArrayList of hashset in java? [closed]

[Solved] Is Java HashSet add method thread-safe?

No, HashSet is not thread-safe. You can use your own synchronization around it to use it in a thread-safe way: boolean wasAdded; synchronized(hset) { wasAdded = hset.add(thingToAdd); } If you really need lock-free performance, then you can use the keys of a ConcurrentHashMap as a set: boolean wasAdded = chmap.putIfAbsent(thingToAdd,whatever) == null; Keep in mind, … Read more

[Solved] Why doesn’t my hashmap work? My object has the property that hashCode() equality implies equals(…) equality [closed]

You can assume that I’m modifying a field of the object after I add the object to the HashMap. That right there is why. Javadoc says: Note: great care must be exercised if mutable objects are used as map keys. The behavior of a map is not specified if the value of an object is … Read more

[Solved] Trim HashSet

“Better” is arguable, but you could use the built-in method UnionWith and some LINQ for a nice one liner to replace your foreach. Think of it as the closest equivalent to an AddRange, except with the restrictions of a set of course. values.Clear(); values.UnionWith(_values.Select(x => x.Trim())); 2 solved Trim HashSet

[Solved] getting ArrayList from HashSet [closed]

Most common way to do it: HashSet<ArrayList<String>> set = assingYourSet(); for (Iterator iterator = set.iterator(); iterator.hasNext();) { ArrayList<String> arrayList = (ArrayList<String>) iterator.next(); // Do Stuff… } 1 solved getting ArrayList from HashSet [closed]