Coggle requires JavaScript to display documents.
Stream
Collection
@Test public void givenStream_thenInitializeList(){ List<String> list = Stream.of("foo", "bar") .collect(Collectors.toList()); assertTrue(list.contains("foo")); }
Collectors.toList()
List
Collectors.toUnmodifiableList()
Map
toMap
Map<String, Integer> result = givenList.stream() .collect(toMap(Function.identity(), String::length))
Set
List<String> list = List.of("foo", "bar", "baz"); Set<String> set = Set.of("foo", "bar", "baz");
var-args
Set.of()
IllegalArgumentException
of()
Map<String, String> map = Map.of("foo", "a", "bar", "b", "baz", "c");
Map<String, String> map = Map.ofEntries( new AbstractMap.SimpleEntry<>("foo", "a"), new AbstractMap.SimpleEntry<>("bar", "b"), new AbstractMap.SimpleEntry<>("baz", "c"));
ArrayList
HashMap
null
NullPointerException
List<String> list = Arrays.asList(new String[]{"foo", "bar"});
java.util.Arrays
varargs
LinkedList
@Test(expected = UnsupportedOperationException.class) public void givenArraysAsList_whenAdd_thenUnsupportedException() { List<String> list = Arrays.asList("foo", "bar"); list.add("baz"); }
@Test public void givenArraysAsList_whenCreated_thenShareReference(){ String[] array = {"foo", "bar"}; List<String> list = Arrays.asList(array); array[0] = "baz"; assertEquals("baz", list.get(0)); }
@Test public void givenAnonymousInnerClass_thenInitialiseList() { List<String> cities = new ArrayList() {{ add("New York"); add("Rio"); add("Tokyo"); }}; assertTrue(cities.contains("New York")); }
@Test public void givenAnonymousInnerClass_thenInitialiseList() { List<String> cities = new ArrayList() { { add("New York"); add("Rio"); add("Tokyo"); } }; assertTrue(cities.contains("New York")); }
final