[JAVA] [Practice] Map method


package map_renshuu;
//Import Map and HashMap classes
import java.util.HashMap;
import java.util.Map;

public class Map1 {

	public static void main(String[] args) {
		//Create Map instance, specify String type for key and int type for value (element)
		//The left side is a Map class to use "rough" polymorphism
		Map<String,Integer> bankList=new HashMap<String,Integer>();

		//<bankList>Enter the key and value in
		bankList.put("Bank of Fukuoka",541);
		bankList.put("West Japan City Bank",312);
		bankList.put("Mizuho Bank",653);
		bankList.put("Japan Post Bank",685);
		bankList.put("Sumitomo Mitsui Banking Corporation",797);

		//<bankList>It is necessary to assign to the variable once to retrieve the value contained in it. use get method
		int sumitomo=bankList.get("Sumitomo Mitsui Banking Corporation");
		System.out.println("Sumitomo Mitsui's bank code is"+sumitomo+"is");
		
		/*----------------------------------------------
remove method(This is output properly when executed, so I'm checking why it is not removed)
		bankList.remove("sumitomo");
		System.out.println(sumitomo);
         ------------------------------------------------*/
		
		//Turn with for statement and output
		//Keys are returned in order on the right side of the for statement
		for(String nini:bankList.keySet()) {
			int value=bankList.get(nini);
			System.out.println(nini+"The bank code is"+value+"is");
		}
		//Output bamkList by itself
		System.out.println(bankList);


	}

}

/*Execution result----------------------------

Sumitomo Mitsui's bank code is 797
797
The Bank of Fukuoka code is 541
Japan Post Bank Bank code is 685
West Japan City Bank Bank code is 312
Mizuho Bank Bank code is 653
Sumitomo Mitsui Banking Corporation Bank code is 797
{Bank of Fukuoka=541,Japan Post Bank=685,West Japan City Bank=312,Mizuho Bank=653,Sumitomo Mitsui Banking Corporation=797}
--------------------------------*/

Recommended Posts

[Practice] Map method
Map method
ruby map method
Stream API map method
About the map method
Method
Practice of linear search method
[Practice] ArrayList
Array practice
Java method
to_i method
java (method)
getRequestDispatcher () method
merge method
[Practice] ArrayList
[Rails] How to use the map method
include method
Array practice 2
initialize method
JAVA (Map)
puts method
Java method
Class method
save! method
getParameter method
[Java] method
ArrayList practice
[Practice] Enumeration
private method
rails method
[Java] method
forEach practice (Part 1: Rewrite from forEach statement to forEach method)