Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

GAMES++
Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

BROWSER UTILITIES
E-mail This Page
Add to Favorites

SITE SEARCH

Web Games++

AFFILIATES
Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials

ADVERTISEMENT

ADVERTISEMENT

How To Use a Hashtable

Java How To: Source Code

Hashtables are very useful for maintaining a 1-to-1 relationship between Objects. With an arbitary key, you can retrieve easily an Object. In the following example, we retrieve a String array with a String.

String[] array1 = {"A","B","C"};
String[] array2 = {"X","Y","Z"};
String[] array3 = {"1","2","3"};

Hashtable arrays = new Hashtable();
arrays.put("Array1", array1);
arrays.put("Array2", array2);
arrays.put("Array3", array3);

String[] resultArray = (String[])(arrays.get("Array2"));
System.out.println(resultArray[0] + ", " + resultArray[1] + ", " + resultArray[2]);

Scan the content of a hashtable

Enumeration keys = hash.keys();

while( keys.hasMoreElements() ) 
{
   Object key = keys.nextElement();
   Object value = hash.get(key);
}

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy