StringTokenizer - reading lines with integers

后端 未结 2 1943
温柔的废话
温柔的废话 2021-01-15 03:32

I have a question about optimization of my code (which works but is too slow...). I am reading an input in a form

X1 Y1
X2 Y2
etc

where Xi,

2条回答
  •  滥情空心
    2021-01-15 04:17

    You could use regex to check if the value is numerical and then convert to integer:

    if(st.nextToken().matches("^[0-9]+$"))
            {
               int x = Integer.parseInt(st.nextToken());
            }
    

提交回复
热议问题