• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pls HELP-- convert string array to int array

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I got a list of check box from jsp


Many thanks for your help and assistand
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, without your explaining how each String in the array should become an int, we can't really answer. Are they Strings like "1", "2", "3"? Are they Strings like "one", "two", "three"? Are they "red", "blue", "green" and the ints should be indexes into some list, somewhere? Without our knowing how each single String should be converted to an int, there's no way to know how to convert the whole array.
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can convert this as:

 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Ajay - let me try your way,

Ernest Friedman-Hill : i forgot to mention, the value of the checkbox will always as "1", "2", "3" "4"...etc..

Many thanks, regards
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can convert this as:

code:


String [] chckbox = request.getParameterValues("jspchckbox");
int[] value = new int[chckbox.length];
for(int i=0; i<chckbox.length; i++)
value[i] = Integer.parseInt(chckbox[i]);



This is what I did, but it is only pick the first item, i check 4 checkboxes on the jsp, so the value should be 1,2,3,4 (actual value)

[code]
String [] chckbox = request.getParameterValues("jspchckbox");
int[] value = new int[chckbox.length];
for(int i=0; i<chckbox.length; i++)
{
value[i] = Integer.parseInt(chckbox[i]);
this.getValues(value); ??? // i invoke the method i had and the value[] array, but return only 1 value from the chckbox instead of 1,2,3,4..
}

Any ideas? Thank you again
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
call the function at the end of the loop
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Ajay S",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Ajay Singh
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to this forum. Thanks for reminding me, have corrected it.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mayura Hayat,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic