What's the fastest way to read from System.in in Java?

前端 未结 9 2095
梦如初夏
梦如初夏 2020-11-30 19:17

I am reading bunch of integers separated by space or newlines from the standard in using Scanner(System.in).

Is there any faster way of doing this in Ja

9条回答
  •  Happy的楠姐
    2020-11-30 20:08

    Reading from disk, again and again, makes the Scanner slow. I like to use the combination of BufferedReader and Scanner to get the best of both worlds. i.e. speed of BufferredReader and rich and easy API of the scanner.

    Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    

提交回复
热议问题