Map TreeMap get values to array Java Android example

import java.util.Map;
import java.util.TreeMap;
 
public class MainClass {
	public static void main(String[] arg) {
 
		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "two sets of;zwei"
				, "three;drei", "four;vier" };
 
		Map<String, String> map = new TreeMap<String, String>();
 
		for (String s : arrayOfString) {
			String[] array = s.split(";");
			String sKey = "", sValue = "";
			if (array.length > 1) {
				sKey = array[0];
				sValue = array[1];
				map.put(sKey, sValue);
			}
		}
    Object[] objectArrayOfValues = map.values().toArray();
	for (int i = 0; i < objectArrayOfValues.length; i++) {
		System.out.println(objectArrayOfValues[i]);
	}
 
 
	}// end main
 
}
/*
vier
eine
drei
zwei
zwei
 */
This entry was posted in Android Examples Code, Array,List,Collections and tagged , , , , , . Bookmark the permalink.


Comments are closed.

4,966 views