• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

StringTokenizer + HashTable

 
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic