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

前端 未结 4 1573
青春惊慌失措
青春惊慌失措 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:37

    Try this :

      // Creation of ArrayList of string
      ArrayList obj = new ArrayList();
    
      // arrayList of string
      obj.add("China 12351235123");
      obj.add("Korea 123532523");
      obj.add("USA 12341235123");
    
    
        Iterator iterator = obj.iterator();
        String str;
        String[] split_str;
        long  value;
        while (iterator.hasNext()) {
            str = iterator.next().toString();
            split_str = str.split(" ");
            String split_2 = split_str[1];
            value = Long.parseLong(split_2);
            System.out.println(value);
        }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题