The code:
StringBuffer sbuffer = new StringBuffer();
Scanner input = new Scanner(System.in);
System.out.println("Enter a string");
sbuffer.append(input.nextLine());
will add your 'next line' to the StringBuffer sbuffer.
This is because input.nextLine() returns a String, and sbuffer.append(...) accepts a variety of arguments, including Strings.
The documentation for a StringBuffer can be found at this Java page.
Likewise, scanner documentation is also available.
These links provide a list of the methods available for each of these classes, along with the arguments/parameters that methods can take. The Java documentation frequently gives examples of use cases.
From the opening paragraph of the StringBuffer documentation:
A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.
String buffers are safe for use by multiple threads. The methods are synchronized where necessary so that all the operations on any particular instance behave as if they occur in some serial order that is consistent with the order of the method calls made by each of the individual threads involved.
StringBuffer a = new StringBuffer(); a.append(scanner.nextLine());StringBufferand some differences with aString. In case you didn't know, 'immutable' just means it can't be changed. AStringis created with some value, and this value cannot be modified later. The same is not true for aStringBufferStringobject. You create a newStringobject which is made up from the previous twoStringobjects. This is why people often have problems with thestringA == stringBorstringA == "expected contents of stringA", and should instead usestringA.equals(stringB);-==compares the objects, whereasequals(...)compares the contents. For a more in-depth example, see this