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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…