How to copy Java Collections list
问题 I have an ArrayList and I want to copy it exactly. I use utility classes when possible on the assumption that someone spent some time making it correct. So naturally, I end up with the Collections class which contains a copy method. Suppose I have the following: List<String> a = new ArrayList<String>(); a.add("a"); a.add("b"); a.add("c"); List<String> b = new ArrayList<String>(a.size()); Collections.copy(b,a); This fails because basically it thinks b isn't big enough to hold a . Yes I know b