When you do a toCharArray the commas are also stored in the elements to avoid this use StringTokenizer with comma as the delimiter.
For example:
String[] s = new String[10];
String param = "invoice number, file name, userid";
StringTokenizer st = new StringTokenizer(param,",");
int i = 0;
while (st.hasMoreTokens())
{
s[i]= st.nextToken();
System.out.println("String[] elements:"+s[i]);
i++;
}
I hope your requirements were met.
Roopa.
Originally posted by Bhasker Reddy:
I have a String like
String param = "invoice number, file name, userid";
How do i convert this into an array and extract each values,
My String param can contain sometimes 3 words(with comma separated) or sometimes 5 or 2 , i get param dynamically.
can anyone suggest what to do