• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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();
}
}
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic