Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

StringTokenizer + HashTable

 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm having trouble in populating HashTable.
I need to create a hashtable with values
Carrier    SpeedyAir
Origin    DEN
Destination    SFO
using string
criteria = "Carrier=SpeedyAir,Origin=DEN,Destination=SFO"



public void criteriaFind(String criteria) throws DatabaseException{
HashTable ht = new HashTable();
StringTokenizer tokens1 = new StringTokenizer(criteria,",");
while(tokens1.hasMoreTokens()) {
StringTokenizer tokens2 = new StringTokenizer(tokens1.nextToken(),"=");
while(tokens2.hasMoreTokens()) {
// Put records in HashTable
}
}

}
Thanks
Dilip
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your class is fine except Hash(T->t)able. Here's the working code. The problem should be somewhere while storing.
import java.util.*;
public class Tok
{
static String criteria = "Carrier=SpeedyAir,Origin=DEN,Destination=SFO";
public static void criteriaFind()
{
Hashtable ht = new Hashtable();
StringTokenizer tokens1 = new StringTokenizer(criteria,",");
while(tokens1.hasMoreTokens())
{
StringTokenizer tokens2 = new StringTokenizer(tokens1.nextToken(),"=");
while(tokens2.hasMoreTokens())
{
// Put records in HashTable
System.out.println( tokens2.nextToken() );
}
}
}
public static void main( String args[])
{
criteriaFind();
}
}
 
    Bookmark Topic Watch Topic
  • New Topic