• 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
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

String Tokenizer Problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a method which returns a String array of elements, i am going to display in a JList. I use a JSplitPane, the Left Side contains a JTree put in a JScrollPane, the Right Side contains the list of elements from the String array.

How to count the elements using the StringTokenizer? I count the elements from the String array using another method, calling the getElements() method which i created previously.

When i count the elements, i only want to count the Map element once, then the rest, i just skip it and don't include in my counting, i also do not want to display the elements. The count i mean here is counting the total number of elements and accumulate it.

So expected output will be something like this:
Map
mapID
simulationID
mapName
mapDesc
mapLength
mapWidth
mapScale
JunctionList
Junction
junctionID
JunctionList
Junction
junctionType
JunctionList
Junction
xJunction
JunctionList
Junction
yJunction
JunctionList
Junction
jConnectedTo
JunctionList
Junction
jConnectedRoadIn
JunctionList
Junction
TrafficLightList
TrafficLight
trafficID
JunctionList
Junction
TrafficLightList
TrafficLight
trafficType
JunctionList
Junction
TrafficLightList
TrafficLight
xTraffic
JunctionList
Junction
TrafficLightList
TrafficLight
yTraffic
...
...
...
(output not complete)

However, now i found it quite wierd that some elements in between do not show up too.

Currently my output now:
mapID
simulationID
mapName
mapDesc
mapLength
mapWidth
mapScale
JunctionList
junctionID
JunctionList
junctionType
JunctionList
xJunction
JunctionList
yJunction
JunctionList
jConnectedTo
JunctionList
jConnectedRoadIn
JunctionList
TrafficLightList
trafficID
JunctionList
TrafficLightList
trafficType

Why Junction and TrafficLight element are missing?

I just add one more line of code which is:


The codings are as follows:



The code to count the elements:



Any idea what is wrong?
How should i modify my code?
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."

http://today.java.net/download/jdk6/doc/api/java/util/StringTokenizer.html
 
Pamela Ng
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Graeme Byers:
"StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead."

jdk6[/b]/doc/api/java/util/StringTokenizer.html]http://today.java.net/download/jdk6/doc/api/java/util/StringTokenizer.html



So how to do it with split method? Sorry, not very good with java...
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is explained here with example.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic