Is there some way of initializing a Java HashMap like this?:
Map test =
new HashMap{\"test\":\"test\",\"test\
You can use Streams In Java 8 (this is exmaple of Set):
@Test
public void whenInitializeUnmodifiableSetWithDoubleBrace_containsElements() {
Set countries = Stream.of("India", "USSR", "USA")
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
assertTrue(countries.contains("India"));
}
Ref: https://www.baeldung.com/java-double-brace-initialization