Tag: collections

52 votes
10 answers
972 views
Why aren't Java Collections remove methods generic?

Why isn't Collection.remove(Object o) generic? Seems like Collection<E> could have boolean remov

avatar
Percy
0 1 0 9
asked 07 September, 2021
63 votes
7 answers
3K views
Convert Enumeration to a Set/List

Is there some one-liner bridge method to dump a given Enumeration to java.util.List or java.util.Set? Somethin

avatar
Omar
0 1 0 9
asked 07 September, 2021
55 votes
6 answers
2K views
LINQ .Any VS .Exists - What&apos;s the difference?

Using LINQ on collections, what is the difference between the following lines of code? if(!coll.Any(i => i

avatar
Virgil
0 1 0 9
asked 07 September, 2021
58 votes
30 answers
1.6K views
Get nth character of a string in Swift programming language

How can I get the nth character of a string? I tried bracket([]) accessor with no luck. var string = "Hello,

avatar
Corrin
0 1 0 9
asked 07 September, 2021
56 votes
19 answers
1.5K views
Why doesn&apos;t java.util.Set have get(int index)?

I'm sure there's a good reason, but could someone please explain why the java.util.Set interface lac

avatar
Kisha
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
705 views
Sort a Map<Key, Value> by values

I am relatively new to Java, and often find that I need to sort a Map<Key, Value> on the values. Since

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
63 votes
30 answers
2.2K views
Initialization of an ArrayList in one line

I wanted to create a list of options for testing purposes. At first, I did this: ArrayList<String> plac

avatar
Dorian
0 1 0 9
asked 07 September, 2021
54 votes
30 answers
924 views
When to use LinkedList over ArrayList in Java?

I've always been one to simply use: List<String> names = new ArrayList<>(); I use the inte

avatar
Sena
0 1 0 9
asked 07 September, 2021
67 votes
30 answers
834 views
How do I efficiently iterate over each entry in a Java Map?

If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained wit

avatar
Daniel
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
2.4K views
What are the differences between a HashMap and a Hashtable in Java?

What are the differences between a HashMap and a Hashtable in Java? Which is more efficient for non-threaded

avatar
Eddie
0 1 0 9
asked 07 September, 2021