STDIN
私からの入力を読み取るために、常にScanner
オブジェクトを使用しました。最近、BufferedInputStream が入力を読み取る最速の方法であるとBufferedInputStream
ここで読みました。にScanner
はさまざまな方法があります ( to read integer
nextInt()
、 to read byte nextByte()
、 to readstring next()
など)。現在、いくつかの文字列 (最大 100000 文字) といくつかの整数を読み取っています。これらの整数によると、 から入力を受け取る for ループをさらに実行しますSTDIN
。以下は、私が今まで使用しているコードスニペットです-
Scanner sc = new Scanner(System.in);
int numOfStr = sc.nextInt();
String inputStr[] = new String[numOfStr];
for (int i = 0; i < numOfStr; i++) {
inputStr[i] = sc.next();
}
}
However with BufferedInputStream
we have only read()
to read input. So how can i differentiate among the inputs? Can somebody please write down the BufferedInputStream
code equivalent to the above Scanner
? Should i use StringTokenizer
class to tokenize to data which i am getting from read()
? Will this not make the whole stuff (reading input from the STDIN
) more slower than Scanner
?