Solved

arrays

Posted on 2001-09-17
2
210 Views
Last Modified: 2010-03-31
using jsp, i have a servlet that queries a database and returns all of the database tables in a pipe delimited string.

my question is this: is there a way to split the string into an array (similar to the split method in javascript), or is there an easy way to iterate through the resultset in the servlet and return an array instead of a string.

is there a better way to do this alltogether? i'm open to suggestions.

if there are multiple answers that i adopt, i will add additional questions and/or increase the points.
0
Comment
Question by:msdixon
2 Comments
 
LVL 1

Accepted Solution

by:
kanthonym earned 100 total points
ID: 6487897
Yes, you can use the StringTokenizer class. This will pewrmit you to iterate through the string and parse out the contents based on the delimiter that your provide.


The following is one example of the use of the tokenizer. The code:

     StringTokenizer st = new StringTokenizer("this is a test");
     while (st.hasMoreTokens()) {
         println(st.nextToken());
     }
 
prints the following output:

     this
     is
     a
     test
 

Constructor Summary
StringTokenizer(String str)
          Constructs a string tokenizer for the specified string.
StringTokenizer(String str, String delim)
          Constructs a string tokenizer for the specified string.
StringTokenizer(String str, String delim, boolean returnDelims)
          Constructs a string tokenizer for the specified string.
0
 
LVL 9

Author Comment

by:msdixon
ID: 6488037
that's what i needed.

works like a champ.

thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now