Initializing list while declaring it is very convenient for quick use. If you have been using Java programming language for quite some time then you must be familiar with syntax of array in Java and how to initialize an arrayin the same line while declaring it as show below:
String[] oldValues = new String[] {"list" , "set" , "map"};
or even shorter :
String[] values = {"abc","bcd", "def"};
Similarly we can also create List and initialize it at same line, popularly known as initializing List in one line example. Arrays.asList() is used for that purpose which returns a fixed size List backed by Array. By the way don’t confuse between Immutable or read only List which doesn’t allow any modification operation including set(index) which is permitted in fixed length List.Here is an example of creating and initializing List in one line :