0

Python code:

str = "123;456;789"
strlist = str.split(";")
strlist = [int("%s" % s) for s in strlist]
print strlist
1
  • 4
    Huh? The third line should be just strlist = [int(s) for s in strlist]. Even better, drop it completely and change the second line to strlist = [int(s) for s in str.split(";")]. Finally, don't use str as a variable name (it overrides the built-in name str which you probably don't want). Commented Jan 21, 2011 at 8:23

2 Answers 2

3
String str = "123;456;789";
String[] strList = str.split(";");

ArrayList<Integer> intList = new ArrayList<Integer>();
for (String s : strList) {
    intList.add(Integer.parseInt(s));
}

System.out.println(intList);
Sign up to request clarification or add additional context in comments.

1 Comment

It would be better to create the ArrayList with the right capacity: new ArrayList<Integer>(strList.length));
0

System.out.println("[123, 456, 789]");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.