When I don’t include the commented line, prevLineBuffer contains “null.” When i do include the commented line it still works, but prints an empty string. Does Java statically allocate space for the declared string and then dynamically allocate space for an additional string in the commented line? Both appear to work…
public class Indexer {
String input;
StringBuilder prevLineBuffer;
Indexer(String inputFileName) throws RuntimeException{
input = inputFileName;
//prevLineBuffer = new StringBuilder();
System.out.print(prevLineBuffer);
}//constructor
}//class
You need to print the result of
.toString(), and.append()something to it, in order to give it something to print. For example:To answer the second half of your question…
From the String docs:
From the StringBuilder docs: