Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

arrays

Posted on 2001-09-17
2
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
kanthonym earned 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

636 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