Hashtable find value by key Java Android example

Hashtable find value by key Java Android basic example.

import java.util.Hashtable;
 
public class MainClass {
	public static void main(String[] arg) {
 
		// english;germany dictionary
		String[] arrayOfString = { "one;eine", "two;zwei", "three;drei" };
 
	    Hashtable hashTable = new Hashtable();
	    for(String s: arrayOfString){
	    	String[] array = s.split(";");
	    	String sKey ="", sValue="";
	    	if(array.length > 1){
	    	sKey = array[0]; sValue = array[1];
	    		hashTable.put(sKey, sValue);
	    	}
	    }
 
       // check if key exists 	    
	   if( hashTable.containsKey("two")){
		System.out.print("two = " + hashTable.get("two"));
	   }
 
	}
}
/*
two = zwei
 */
This entry was posted in Android Examples Code, Array,List,Collections and tagged , , , , , . Bookmark the permalink.


Comments are closed.



9,073 views