Solved

arrays

Posted on 2001-09-17
2
228 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

776 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