Im very new to programming and im taking a course. It wants me to create a string object using string buider. I think i figured it out StringBuilder str = new StringBuilder(test);
. It makes a string object(i think) with the name test. I wanted to be able to add 'values' inside of it. Like the string object "test" also has like a sub category for like "sub test". I also dont know how I would access and call on those specific values. as i said before im new so I am probably missing a method or something basic that I can use. Thanks.
The only other thing I could think of that would add two values together is a 2 dim array but the class wants me to use string objects and string builder.
CodePudding user response:
The code you showed makes a StringBuilder
with contents of 'test'. It isn't a string. You can get the String value from it by calling toString()
StringBuilder sb = new StringBuilder("initial value.");
sb.append("test");
sb.append("[sub test]");
String val = sb.toString();
System.out.println(val);
Try the code, experiment with it. See what prints.