I'm trying to initialize a StringBuilder with "". These are 2 samples, the first one doesn't work while the second one works. Can anyone explain a bit more? Is this because StingBuilder is an object?
for (StringBuilder element : sb){
element = new StringBuilder("");
} // this solution doesn't work, print sb[0] = null
for(int i=0; i<sb.length; i++){
sb[i] = new StringBuilder("");
}
I'm expecting both would work.
sb? Please show a complete code example that we can copy/paste, compile, and run ourselves without any additional errors than what you are asking about. This means you need to declare all variables that you use and include validSystem.out.println()calls rather than just a comment.int[]to illustrate what you are doing rather than aStringBuilder[].