File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Tokenizer Problem

 
Pamela Ng
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Graeme Byers
Ranch Hand
Posts: 127
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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...
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is explained here with example.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic