HashMap
has a constructor that can take another Map
, so you can create a HashMap
by passing it whatever Map.of(...)
produces:
HashMap<String, String> map = new HashMap<>(Map.of("k1", "v1", "k2", "v2"));
Likewise for ArrayList
and List.of(...)
.
Related Contents:
- Why is January month 0 in Java Calendar?
- Hibernate SessionFactory vs. JPA EntityManagerFactory
- Java 8 – Best way to transform a list: map or foreach?
- Convert character to ASCII numeric value in java
- When do you use varargs in Java?
- Format a date using the new date time API
- What is the concept of erasure in generics in Java?
- How to create custom exceptions in Java? [closed]
- How to work around the stricter Java 8 Javadoc when using Maven
- What determines the lifecycle of a component (object graph) in Dagger 2?
- Java: How to Indent XML Generated by Transformer
- How do HashTables deal with collisions?
- Why is Java’s boolean primitive size not defined?
- Class JavaLaunchHelper is implemented in both. One of the two will be used. Which one is undefined [duplicate]
- Regexp Java for password validation
- Maven- No plugin found for prefix ‘spring-boot’ in the current project and in the plugin groups
- How to convert a string Date to long millseconds
- How can I reference my Java Enum without specifying its type
- Java: what exactly is the difference between NIO and NIO.2?
- Option to ignore case with .contains method?
- What is the size of a boolean variable in Java?
- How can I mark a foreign key constraint using Hibernate annotations?
- Difference between System.load() and System.loadLibrary in Java
- Is it possible to disable jsessionid in tomcat servlet?
- How does Keep-alive work with ThreadPoolExecutor?
- JDK documentation in IntelliJ IDEA on Mac OS X
- Is there a standard for inclusive/exclusive ends of time intervals?
- How to format message with argument names instead of numbers?
- Faster algorithm to find unique element between two arrays?
- Difference between Collections.sort(list) and list.sort(Comparator)
- Logger vs. System.out.println
- Can Java 9 run on a 32-bit OS?
- print spaces with String.format()
- Boolean.getBoolean(“true”) returns false
- is it possible to “go back” in java eclipse debugger like dragging the arrow in VS
- Is there anything like VirtualEnv for Java?
- How can I pass a Class as parameter and return a generic collection in Java?
- Workbench section not showing in apache jmeter
- Importing SSL Certificate into Eclipse
- Using Scala from Java: passing functions as parameters
- jarsigner: This jar contains entries whose certificate chain is not validated
- How to export all my Intellij code styles to a .editorconfig file?
- Jackson serializes a ZonedDateTime wrongly in Spring Boot
- nameof equivalent in Java
- How do you set a value in the IntelliJ Registry?
- Stripping HTML tags in Java [duplicate]
- How do you get the screen width in java?
- Why is comparing floats inconsistent in Java?
- org.junit.platform.commons.JUnitException: TestEngine with ID ‘junit-jupiter’ failed to discover tests
- What is a static interface in java?