In solving the problems of the learning site, I did it while investigating various methods to acquire the contents of the map, so I summarized it as a memorandum.
I will take out the following contents.
Map<String, String> fruit = new LinkedHashMap<String, String>();
fruit.put("Apple", "apple");
fruit.put("Mandarin orange", "orange");
fruit.put("Grape", "grape");
fruit.put("banana", "banana");
Use keySet ()
.
for (String japanese : fruit.keySet()) {
System.out.println(japanese);
}
The results are as follows.
Apple
Mandarin orange
Grape
banana
Use values ()
.
for (String english : fruit.values()) {
System.out.println(english);
}
The results are as follows.
apple
orange
grape
banana
Use ʻentrySet () `.
for (Map.Entry<String, String> fruitName : fruit.entrySet()) {
System.out.println(fruitName.getKey() + "Is in english" + fruitName.getValue());
}
The results are as follows.
Apples are apple in english
Mandarin orange in English
Grape in English
Banana is banana in English
It has become a very simple way of summarizing, but this time it is over.
I think there are other ways, but I would like to study in the future.
Recommended Posts