Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert values stored in the String array to Integer array in Java [closed]

Tags:

java

arrays

Here I want to convert sting array values into integer array,Need to store all string values into integer array, Here is the string array:

private String[] aa = {"70","80","99","140","150","199","200","300",
                       "349","350","400","499","500","501","900","1000","1100","1200"};
like image 800
Mani Avatar asked Sep 14 '15 11:09

Mani


3 Answers

If you're on Java8, you could do:

int[] array = Stream.of(aa).mapToInt(Integer::parseInt).toArray();
like image 176
Konstantin Yovkov Avatar answered Oct 19 '22 00:10

Konstantin Yovkov


Loop through the array and convert it to int.

int []intArray = new int[strArray.length];
int i = 0;
for(String s : strArray)
  intArray[i ++] = Integer.parseInt(s);
System.out.println(Arrays.toString(intArray));
like image 28
Uma Kanth Avatar answered Oct 18 '22 22:10

Uma Kanth


    int[] bb = new int[aa.length];
    for (int i = 0; i < aa.length; i++) {
        bb[i] = Integer.parseInt(aa[i]);
    }

http://ideone.com/uJCAX2

like image 1
Daniel Alder Avatar answered Oct 19 '22 00:10

Daniel Alder