Why is this ArrayList throwing a ConcurrentModificationException when I try to remove an element?

I’m trying to remove a particular element from Arraylist, it throws an ConcurrentModificationException ArrayList ar = new ArrayList(); ar.add(“a”); ar.add(“b”); ar.add(“c”)…

How to convert comma-separated String to List?

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that? String commaSeparated =…

How to iterate a HashMap using the natural entrySet() order?

My Map contains keys sorted in alphabetical order. When I display it, I’m using entrySet().iterator(), but my results are not in the alphabetical order. How can I get my results in order?

How can I initialize an ArrayList with all zeroes in Java?

It looks like arraylist is not doing its job for presizing: // presizing ArrayList list = new ArrayList(60); Afterwards when I try to access it: list.get(5) …

Print array without brackets and commas

I’m porting a Hangman game to Android and have met a few problems. The original Java program used the console, so now I have to somehow beautify the output so that it fits my Android layout. How do I …

Java – Collections.sort() performance

I’m using Collections.sort() to sort a LinkedList whose elements implements Comparable interface, so they are sorted in a natural order. In the javadoc documentation its said this method uses …

Why is a ConcurrentModificationException thrown and how to debug it

I am using a Collection (a HashMap used indirectly by the JPA, it so happens), but apparently randomly the code throws a ConcurrentModificationException. What is causing it and how do I fix this …

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

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 …