-2

I have a string array for an app I am making. It loads an EditText, so I will instead create a dummy one.

String[] s = ["1","2","3"];

How would I change String s into an integer array, such as Int i?

Int[] i = [1,2,3];

I have tried Integer.parseInt on the string array but it does not work. Does anyone know how to convert string arrays into integer arrays?

4
  • 5
    A simple for-loop will work. Commented Aug 19, 2014 at 3:02
  • 2
    do Integer.parseInt on each element of the array Commented Aug 19, 2014 at 3:03
  • Multiply each array value by 1 and it will convert them to integers. Commented Aug 19, 2014 at 3:03
  • @DevlshOne sarcastic I hope? Commented Aug 19, 2014 at 4:01

1 Answer 1

1

Something like the following should work:

string[] s = ["1","2","3"];
int[] i = new int[s.length()];
for (int j = 0; j < s.length(); j++)
    i[j] = Integer.parseInt(s[j]);
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.