When I input a string of 4500 characters followed by a newline feed in Java console, it displays input line is too long
runtime error in the terminal.
I have tried using both Scanner
and BufferedReader
, but no success.
When I input a string of 4500 characters followed by a newline feed in Java console, it displays input line is too long
runtime error in the terminal.
I have tried using both Scanner
and BufferedReader
, but no success.
My advice when working with big strings is to use StringBuilder Class, here is an example:
import java.util.*;
public class Main {
public static void main(String[] args) {
String someString;
Scanner scanner = new Scanner(System.in);
StringBuilder builder = new StringBuilder();
builder.append(scanner.nextLine());
someString = builder.toString();
System.out.println(someString);
}
}