The collections framework in java.util provides a number of generic classes for sets of data with functionality that can't be provided by regular arrays.
OR
The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.
Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.
A simple way to construct a List from individual data values is to use java.utils.Arrays method Arrays.asList :
List<String> data =Arrays.asList("ab","bc","cd","ab","bc","cd");List<String> list =newArrayList<>(data); // will add data as isSet<String> set1 =newHashSet<>(data); // will add data keeping only unique valuesSortedSet<String> set2 =newTreeSet<>(data); // will add data keeping unique values and sortingSet<String> set3 =newLinkedHashSet<>(data); // will add data keeping only unique values and// preserving the original order
List<String> names=newArrayList<>(Arrays.asList("Clementine","Duran","Mike"));names.forEach(System.out::println);// If we need parallelism usenames.parallelStream().forEach(System.out::println);for (String name : names) {System.out.println(name);}for (int i =0; i <names.size(); i++) {System.out.println(names.get(i));}
Using Iterator
//Creates ListIterator which supports both//forward as well as backward traverselListIterator<String> listIterator =names.listIterator();//Iterates list in forward directionwhile(listIterator.hasNext()){System.out.println(listIterator.next());}//Iterates list in backward direction once reaches // the last element from above iterator in forward directionwhile(listIterator.hasPrevious()){System.out.println(listIterator.previous());}