URGENT!!!-how to split id (|)


 I have a delete.jsp that receives ids such as user1|user2|user3

String[] id = request.getParameterValues("id") ;

    for(int i=0; i < id.length; i++)



      String Query = "delete FROM volunteer where username='"+id[i]+"'";
      int status= statement.executeUpdate(Query);


  if(status != 0)
   out.println("Entry successfully deleted.");
  out.println("Deletion not successful");



My problem is id[0] is user1|user2|user3

i need to split it into

id[2]=user3 and etc

i mean discard | and put into array.

Pls help , i need it urgently
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


It's quite simple when using StringTokenizer:

import java.util.*;
String id = request.getParameter("id");
StringTokenizer parser = new StringTokenizer(id,"|");
while (parser.hasMoreTokens()) {
   String query = "DELETE FROM volunteer WHERE username = '" + parser.nextToken() + "'";

Good luck!
well first I am not sure why you are getting id[0] as user1|user2 format but.. this is what you can do..

StringTokenizer st = new StringTokenizer(id[0],"|");
String[] ar = new String[st.countTokens()];
int i=0;
This will put all the stuff in String array ar.
Hope this helps

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can use StringTokenizer for this.

Something like this

String ids="user1|user2|user3";
StringTokenizer tokenizer = new StringTokenizer(ids,"|");

String[] ids = new String[tokenizer.countTokens()];
int i = 0;
for (int i = 0; i< tokenizer.countTokens(); i++)
  ids[i] = tokenizer.nextToken();
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

:(( too late again
Mick BarryJava DeveloperCommented:
String names = ids.split("|");
gonna work only with JDK1.4...............
thats why I rely more on tokenizer
Mick BarryJava DeveloperCommented:
I realise that, just offering it as an option if Jasbir21 is running 1.4.
just a comment:

String[] names = ids.split("|");

array is returned... :)

Mick BarryJava DeveloperCommented:
> array is returned... :)

Oops :-)
Jasbir21Author Commented:
I am very sorry for the late response, i got stuck in another question, that i couldn't start with this until that problem was not solved.the program did not work , now it does.

  Very very sorry..

Thanks you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.