How to pick up only integer data from an ArrayList of String

前端 未结 4 1564
青春惊慌失措
青春惊慌失措 2021-01-29 11:48

I read a text file and put the data into an ArrayList of String.

The data is like

China 12351235123 Korea 123532523 USA 1234123         


        
4条回答
  •  有刺的猬
    2021-01-29 12:43

    You can use Regex as SLY suggested, or you can go over your list and split the object into two parts: 'country' and 'number' using:

    for(String s : array){
        String[] parts = s.split(" ");
        long number = Long.parseLong(parts[1]);
        System.out.println(number);
    }
    

    NOTE: the invariant is that each element contains two parts with the delimiter 'white space', and the second part is a number.

提交回复
热议问题