File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes String Tokenizer Problem  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Tokenizer Problem  " Watch "String Tokenizer Problem  " New topic
Author

String Tokenizer Problem

Pamela Ng
Greenhorn

Joined: Dec 20, 2008
Posts: 3
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?
Graeme Byers
Ranch Hand

Joined: Apr 16, 2004
Posts: 127
"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

Joined: Dec 20, 2008
Posts: 3
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...
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374
It is explained here with example.
 
jQuery in Action, 2nd edition
 
subject: String Tokenizer Problem
 
Similar Threads
StringTokenizer
converting String to an array
Can StringTokenizer ignore whitespace??
declaring array of vectors
Droplet Properties