Initialization List with values in one row in Java

Java 9:
List.of(“a”, “b”, “c”);
Set.of(“a”, “b”, “c”);

Java 8:
Stream.of(“a”, “b”, “c”).collect(Collectors.toList());
Stream.of(“a”, “b”, “c”).collect(Collectors.toCollection(ArrayList::new));

Older:
Collections.singletonList();
Arrays.asList();
new ArrayList() {{ add(“a”); add(“b”); add(“c”); }};

Leave a comment

Your email address will not be published. Required fields are marked *