java.util.HashMap.keySetのサンプル

サンプルコード

package com.arkgame;

import java.util.HashMap;

public class HashMapDemo {

	public static void main(String[] args) {
		// Creating an empty HashMap
		HashMap<String, Integer> cftMap = new HashMap<String, Integer>();

		// Mapping int values to string keys
		cftMap.put("aa", 8);
		cftMap.put("4", 10);
		cftMap.put("cc", 15);
		cftMap.put("dd", 20);
		cftMap.put("ee", 25);

		// Displaying the HashMap
		System.out.println("Initial Mappings: " + cftMap);

		// Using keySet() to get the set view of keys
		System.out.println(" set is: " + cftMap.keySet());

	}

}

結果
Initial Mappings: {aa=8, cc=15, dd=20, ee=25, 4=10}
set is: [aa, cc, dd, ee, 4]

Java

Posted by arkgame