package com.concretepage;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
public class HashMapToArrayListExample {
public static void main(String[] args) {
HashMap<String, String> studentPerformanceMap = new HashMap<String, String>();
//Adding elements to HashMap
studentPerformanceMap.put("John Kevin", "Average");
studentPerformanceMap.put("Rakesh Sharma", "Good");
studentPerformanceMap.put("Prachi D", "Very Good");
studentPerformanceMap.put("Ivan Jose", "Very Bad");
studentPerformanceMap.put("Smith Jacob", "Very Good");
studentPerformanceMap.put("Anjali N", "Bad");
//Getting Set of keys
Set<String> keySet = studentPerformanceMap.keySet();
ArrayList<String> listOfKeyValues = new ArrayList<String>(keySet);
for(String keys : listOfKeyValues) {
//System.out.println(keys);
}
Collection<String> ref = studentPerformanceMap.values();
ArrayList<String> values1 = new ArrayList<String>(ref);
for(String values2 : values1) {
System.out.println(values2);
}
Set<Entry<String,String>> home = studentPerformanceMap.entrySet();
ArrayList<Entry<String, String>> homeRef = new ArrayList<Entry<String,String>>(home);
for(Entry<String, String> reference : homeRef) {
System.out.println("reference.getKey " +reference.getKey() + "--" + reference.getValue());
}
}
}
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Set;
public class HashMapToArrayListExample {
public static void main(String[] args) {
HashMap<String, String> studentPerformanceMap = new HashMap<String, String>();
//Adding elements to HashMap
studentPerformanceMap.put("John Kevin", "Average");
studentPerformanceMap.put("Rakesh Sharma", "Good");
studentPerformanceMap.put("Prachi D", "Very Good");
studentPerformanceMap.put("Ivan Jose", "Very Bad");
studentPerformanceMap.put("Smith Jacob", "Very Good");
studentPerformanceMap.put("Anjali N", "Bad");
//Getting Set of keys
Set<String> keySet = studentPerformanceMap.keySet();
ArrayList<String> listOfKeyValues = new ArrayList<String>(keySet);
for(String keys : listOfKeyValues) {
//System.out.println(keys);
}
Collection<String> ref = studentPerformanceMap.values();
ArrayList<String> values1 = new ArrayList<String>(ref);
for(String values2 : values1) {
System.out.println(values2);
}
Set<Entry<String,String>> home = studentPerformanceMap.entrySet();
ArrayList<Entry<String, String>> homeRef = new ArrayList<Entry<String,String>>(home);
for(Entry<String, String> reference : homeRef) {
System.out.println("reference.getKey " +reference.getKey() + "--" + reference.getValue());
}
}
}
No comments:
Post a Comment