I've put together to organize java array types, list types, and map types. I've only used the LL language, so java feels pretty confusing. ..
java
String[] demo_array = new String[3];
java
List<String> demo_list = new ArrayList<>();
java
Map<String, String> demo_map = new HashMap<>();
Assign with Array [index] = value
demo_array[0] = "Red";
demo_array[1] = "yellow";
demo_array[2] = "Green";
Assign with List.add (value)
demo_list.add("Red");
demo_list.add("yellow");
demo_list.add("Green");
Substitute with HashMap.put (key, value).
demo_map.put("red","Red");
demo_map.put("yellow","yellow");
demo_map.put("green","Green");
Get with array [index]
//Get array
String color_red = demo_array[0];
//Get array (batch)
for (String color : demo_array) {
System.out.println(color);
}
Get with list.get (index).
//Get value
String color_yellow = demo_list.get(1);
//Get value(Bulk)
for (String color : demo_list) {
System.out.println(color);
}
//With lambda..
demo_list.forEach(value -> System.out.println(value));
Obtained with HashMap.get (key).
//Get value
String color_green = demo_map.get("green");
//Get value(Bulk)
for (String key : demo_map.keySet()) {
System.out.println(demo_map.get(key));
}
//With lambda..
demo_map.forEach((key, value) -> {
System.out.println(key);
System.out.println(value);
});
Recommended Posts