In java there is no such way (method) by which you can directly get a int array
by passing String array
So u must write some method to do this...
and if there is condition that you must not have to use loop then ...i write a code by adding some more code in Adel Boutros may u get help from this but its better to you loop.. :)
public class Test {
public static void main(String[] args) {
String s = "1,2,3,4,5";
int size = 0;
int[] arr = new int[s.split(",").length];
findInt(s, arr, size);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
static void findInt(String s, int[] arr, int index) {
String aa = null;
if (s == null) {
return;
}
if (s.length() != 1) {
String text = s.substring(0, s.indexOf(","));
arr[index] = Integer.parseInt(text);
} else {
arr[index] = Integer.parseInt(s);
}
if (s.length() != 1) {
aa = s.substring(s.indexOf(",") + 1, s.length());
}
findInt(aa, arr, ++index);
}
}