Convert String to array of integer in java

后端 未结 5 1916
悲&欢浪女
悲&欢浪女 2021-01-29 15:01

Outline how a Java program could convert a string such as “1,2,3,4,5” into an array ({1, 2, 3, 4,5})

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 15:25

    From zvzdhk:

    String[] array = "1,2,3,4,5".split(",");
    

    Then, parse your integers:

    int[] ints = new int[array.length];
    for(int i=0; i

提交回复
热议问题