Solved

arrays

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 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