[JAVA] How to get the contents of Map using for statement Memorandum


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

Get only key

Use keySet ().

       for (String japanese : fruit.keySet()) {

The results are as follows.

Mandarin orange

Get only value

Use values ().

       for (String english : fruit.values()) {

The results are as follows.


Get key and value

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

How to get the contents of Map using for statement Memorandum
[Rails] How to get the contents of strong parameters
How to check for the contents of a java fixed-length string
Customize how to divide the contents of Recyclerview
How to get today's day of the week
[Java] How to get the authority of the folder
How to specify index of JavaScript for statement
[Java] How to get to the front of a specific string using the String class
[Ruby On Rails] How to search the contents of params using include?
[Java] How to get the URL of the transition source
[Java] How to get the maximum value of HashMap
[Java] How to easily get the longest character string of ArrayList using stream
[Java] How to get HashMap elements by loop control using extended for statement
[Android] How to get the setting language of the terminal
How to loop Java Map (for Each / extended for statement)
[Swift] How to get the document ID of Firebase
How to get the class name of the argument of LoggerFactory.getLogger when using SLF4J in Java
[Java] Get Map key / value pairs using extended for statement
How to get the longest information from Twitter as of 12/12/2016
The idea of C # (lambda expression, for statement) to chew
[Ruby] How to retrieve the contents of a double hash
How to output array values without using a for statement
How to change the contents of the jar file without decompressing
[jsoup] How to get the full amount of a document
[Rails] How to get the URL of the transition source and redirect
[Swift5] How to get an array and the complement of arrays
[Swift UI] How to get the startup status of the application [iOS]
[Rails] How to change the page title of the browser for each page
How to get the id of PRIMAY KEY auto_incremented in MyBatis
[For beginners] How to get the Ruby delayed railway line name
How to make a groundbreaking diamond using Java for statement wwww
How to get the length of an audio file in java
How to increment the value of Map in one line in Java
How to get the latest live stream ID for a channel without using the YouTube Data API
[Rails] How to use the map method
How to determine the number of parallels
[Java] How to get the current directory
How to sort the List of SelectItem
How to get the date in java
I want to display the number of orders for today using datetime.
How to switch the display of the header menu for each transition page
How to build an environment for any version of Ruby using rbenv
[Java] [ibatis] How to get records of 1-to-N relationship with List <Map <>>
How to get the absolute path of a directory running in Java
[For Rails beginners] Summary of how to use RSpec (get an overview)
How to find the cause of the Ruby error
Compare the speed of the for statement and the extended for statement.
Implement the star five function using the for statement
I want to var_dump the contents of the intent
[For beginners] How to implement the delete function
Output of how to use the slice method
[Java] (for MacOS) How to set the classpath
How to display the result of form input
[Java] How to get the redirected final URL
[Swift] How to get the number of elements in an array (super basic)
How to get the query string to actually issue when using PreparedStatement with JDBC
graphql-ruby: How to get the name of query or mutation in controller Note
How to get the ID of a user authenticated with Firebase in Swift
How to display the amount of disk used by Docker container for each container
I managed to get a blank when I brought the contents of Beans to the textarea
How to delete / update the list field of OneToMany