| Author |
Pls HELP-- convert string array to int array
|
jay lai
Ranch Hand
Joined: Apr 04, 2002
Posts: 180
|
|
Hello, I got a list of check box from jsp Many thanks for your help and assistand
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
|
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.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Ajay Singh
Ranch Hand
Joined: Dec 13, 2006
Posts: 182
|
|
You can convert this as:
|
 |
jay lai
Ranch Hand
Joined: Apr 04, 2002
Posts: 180
|
|
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
Joined: Apr 04, 2002
Posts: 180
|
|
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
Joined: Dec 13, 2006
Posts: 182
|
|
call the function at the end of the loop
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56202
|
|
"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
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ajay Singh
Ranch Hand
Joined: Dec 13, 2006
Posts: 182
|
|
|
I am new to this forum. Thanks for reminding me, have corrected it.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9950
|
|
Mayura Hayat, Your post was moved to a new topic.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
 |
|
|
subject: Pls HELP-- convert string array to int array
|
|
|