I have developed a array list something like this
ArrayList list = new ArrayList();
list.add(\"1\");
list.add(\"8\");
list.add(\"8\"
If you just need a set of numbers, then use HashSet
and not a List
. If you need to preserve the order by which you are putting the numbers, use LinkedHashSet
. As for removal, always prefer the version with the iterator
, even though in your particular case the performance may be comparable. The idiom with iterator
is more widely applicable than indexing, for example if you used a LinkedList
, indexing would result in disastrous performance.