Skip to content
Advertisement

Tag: data-structures

Why doesn’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 lacks get(int Index), or any similar get() method? It seems that sets are great for putting things into, but I can’t find an elegant way of retrieving a single item from it. If I know I want the first item, I can use set.iterator().next(), but

Equivalent of PHP’s print_r in Java?

last time I asked how to populate a data structure here. Now I would like to know if there’s something in Java, like the print_r I use in PHP, to represent what I have populated in the Maps and lists without having to do my own algorithm. Any ideas? Answer Calling toString on the collection should return a string containing

Advertisement