File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Pls HELP-- convert string array to int array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pls HELP-- convert string array to int array" Watch "Pls HELP-- convert string array to int array" New topic
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: 24187
    
  34

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: 61768
    
  67

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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: 11499
    
  16

Mayura Hayat,
Your post was moved to a new topic.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pls HELP-- convert string array to int array