Java doesn’t support associative arrays, however this could easily be achieved using a Map
. E.g.,
Map<String, String> map = new HashMap<String, String>(); map.put("name", "demo"); map.put("fname", "fdemo"); // etc map.get("name"); // returns "demo"
Even more accurate to your example (since you can replace String with any object that meet your needs) would be to declare:
List<Map<String, String>> data = new ArrayList<>(); data.add(0, map); data.get(0).get("name");
See the official documentation for more information
Related Posts:
- ConcurrentHashMap and Hashtable in Java
- What is a hash function in java?
- Printing a java map Map
– How? - What is a hash function in java?
- What are the differences between a HashMap and a Hashtable in Java?
- Exception in thread “main” java.lang.StackOverflowError
- Difference between HashSet and HashMap?
- Exception in thread “main” java.lang.StackOverflowError
- Iterate through a HashMap [duplicate]
- C# Java HashMap equivalent
- C# Java HashMap equivalent
- Iterate through a HashMap [duplicate]
- What is the significance of load factor in HashMap?
- How to update a value, given a key in a hashmap?
- Collision resolution in Java HashMap
- Hashtable, HashMap, HashSet , hash table concept in Java collection framework
- Difference between HashMap and Map in Java..?
- Java Hashmap: How to get key from value?
- Sorting HashMap by values
- How to sort Map values by key in Java?
- HashMap get/put complexity
- What is the difference between the HashMap and Map objects in Java?
- “Cannot create generic array of ..” – how to create an Array of Map
? - Map of maps – how to keep the inner maps as maps?
- toring and Retrieving ArrayList values from hashmap
- Failed to write core dump. minidumps are not enabled by default on client version of windows
- What is .crt and .key files and how to generate them?
- How do I resolve ClassNotFoundException?
- Editor does not contain a main type in Eclipse [duplicate]
- How to replace � in a string
- How to decrypt a SHA-256 encrypted string?
- What’s the C++ version of Java’s ArrayList
- Can’t find mysqladmin on Mac OSX 10.6.8
- What is an AssertionError? In which case should I throw it from my own code?
- How to write a Unit Test?
- Java optional parameters
- Why would a “java.net.ConnectException: Connection timed out” exception occur when URL is up?
- Compiling a java program into an executable
- Java Installation Not Completed / Unable to install Java
- How can I open Java .class files in a human-readable way?
- Convert an integer to an array of characters : java
- How to compare dates in Java?
- How to convert int[] into List
in Java? - Java integer-double division confusion
- Example of O(n!)?
- A message body writer for Java class java.util.ArrayList and MIME media type application/json was not found
- How to efficiently remove duplicates from an array without using Set
- How to master Java?
- Understanding the difference between null and ‘\u000’ in Java
- How do you make a deep copy of an object?
- what does Dead Code mean under Eclipse IDE Problems Section
- How can I create an Array of ArrayLists?
- Create a List of primitive int?
- Compiling error: Return type for the method is missing
- Can not deserialize instance of java.lang.String out of START_OBJECT token
- Range of valid character for a base 64 encoding
- How to parse JSON boolean value?
- How to create an 2D ArrayList in java?
- Insert Dimensions to complete Expression/ReferenceType
- Unable to locate tools.jar
- Possible lossy conversion from double to float, given float values?
- how to fix EXE4J_JAVA_HOME, No JVM could be found on your system error?
- Error: ‘else’ without ‘if’
- String.format() to format double in Java
- Extending from two classes
- Web server failed to start. Port 8080 was already in use. Spring Boot microserviceWeb server failed to start. Port 8080 was already in use. Spring Boot microservice
- Any implementation of Ordered Set in Java?
- Could not resolve placeholder in string value
- All inclusive Charset to avoid “java.nio.charset.MalformedInputException: Input length = 1”?
- javac error: Class names are only accepted if annotation processing is explicitly requested
- JOptionPane YES NO OPTION
- How to check if a String is numeric in Java
- How to get today’s Date?
- Creating a random string with A-Z and 0-9 in Java
- java.lang.ArithmeticException: / by zero
- How to create JSON Object using String?
- How to repaint a JPanel after have drawn on it?
- Why doesn’t RecyclerView have onItemClickListener()?
- Inverse Logistic Function / Reverse Sigmoid Function
- How can I check if a single character appears in a string?
- Big Oh for (n log n)
- Invalid initial heap size. Could not create the Java virtual machine
- implicit super constructor object() is undefined. must explicitly invoke another constructor
- How to convert a String into an ArrayList?
- Making a deep copy of a LinkedList in java
- How do I join two lists in Java?
- How to insert multiple tabs string in java?
- Java methods getting euclidean distance
- Setting background color for a JFrame
- Does java have “get line”?
- User Input not working with keyboard.nextLine() and String (Java)
- javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake during web service communicaiton
- Generate UML Class Diagram from Java Project
- how to download image from any web page in java
- how to convert .java file to a .class file
- Adding a Scrollable JTextArea (Java)
- Java FileWriter with append mode
- How can I get the count of line in a file in an efficient way?
- The import org.junit cannot be resolved
- Wrong project is being run in Eclipse