Reputation: 141
I'm aware of various methods for reading a String from the user's keyboard in Java (Scanner, Console, BufferedReader), however, none of them seems to be capable to accept a given String that the user can edit.
To rephrase it in code, I'm looking for something like this:
Scanner sc = new Scanner(System.in);
System.out.print("Please edit as you like: " + s);
s = sc.nextLine(s);
As this seems so simple, am I overlooking something? Or is this really not possible in Java without a GUI?
Upvotes: 1
Views: 934
Reputation: 1
If you are trying to edit an existing String, then it's not possible. String is immutable, you can use StringBuilder or create a new String with the new value.
Upvotes: 0
Reputation: 105
Doesn't look like it will be possible. There are similar posts discussing this. Java: populating Scanner with default value on Scanner.nextLine();
A few options have been discussed in there but even the people providing those options are clear that it doesn't meet the stated requirment
Upvotes: 1