There are multiple ways to create and initialize list in one line. Some examples:
//Using Double brace initialization, creates a new (anonymous) subclass of ArrayListList<String> list1 = new ArrayList<>() {{ add("A"); add("B"); }};//Immutable ListList<String> list2 = List.of("A", "B");//Fixed size list. Can't add or remove element, though replacing the element is allowed.List<String> list3 = Arrays.asList("A", "B");//Modifiable listList<String> list4 = new ArrayList<>(Arrays.asList("A", "B"));//Using Java Stream, no guarantees on the type, mutability, serializability, or thread-safetyList<String> list5 = Stream.of("A", "B").collect(Collectors.toList());//Thread safe ListList<String> list6 = new CopyOnWriteArrayList<>(Arrays.asList("A", "B"));