Study java arrays, lists, maps

Introduction

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. ..

Type declaration

Array

java


String[] demo_array = new String[3];

list

java


List<String> demo_list = new ArrayList<>();

map

java


Map<String, String> demo_map = new HashMap<>();

Value assignment

Array

Assign with Array [index] = value

demo_array[0] = "Red";
demo_array[1] = "yellow";
demo_array[2] = "Green";

list

Assign with List.add (value)

demo_list.add("Red");
demo_list.add("yellow");
demo_list.add("Green");

map

Substitute with HashMap.put (key, value).

demo_map.put("red","Red");
demo_map.put("yellow","yellow");
demo_map.put("green","Green");

Get

Array

Get with array [index]

//Get array
String color_red = demo_array[0];
//Get array (batch)
for (String color : demo_array) {
    System.out.println(color);
}

list

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));

map

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

Study java arrays, lists, maps
Combine Java8 lists
Let's study Java
[Java] About arrays
[Java] Study notes
About Java arrays
Java 8 study (repeatable)
Java study memorandum
[Java 8+] Merge maps
Study Java Silver 1
Java, about 2D arrays
Combine arrays in Java
Java Silver Study Day 1
[Java ~ Method ~] Study memo (5)
Java study # 1 (typical type)
[Java ~ Array ~] Study memo 4
My Study Note (Java)
Compare Lists in Java
Nesting Java Lists together
Study Java # 2 (\ mark and operator)
Item 28: Prefer lists to arrays
Java Silver Study Method Memo
[Java ~ Boolean value ~] Study memo (2)
Java study # 7 (branch syntax type)
Java study memo 2 with Progate
Study Java with Progate Note 1
[Java] Combine multiple Lists (Collections)
How to study Java Silver SE 8
Summary of [Java silver study] package
[In-house study session] Java exception handling (2017/04/26)
[Study session memo] Java Day Tokyo 2017
Java study # 4 (conditional branching / if statement)
Orcacla Java Bronze SE 7/8 Qualification Study
Java, arrays to start with beginners
Java study # 5 (iteration and infinite loop)
[Processing × Java] How to use arrays
How arrays work in Java (illustration)