?Every time you are putting a plus between two strings you are creating a new string.
In Java strings are immutable, once you create a string you can never change it. It looks like you changed it , but it's not true. You are creating a new string, you are not appending to the existing string.
Use StringBuilder class instead. StringBuilder appends new content, it does not create a new string builder object which is more efficient. -light weight because it's not thread safe.
-thread safe version of StringBuilder.
-tab and a new line System.out.println("Here is some text \t that was tab \n and this is a new line");
-
Embedding special formatting characters 10 cahracters wide on left %10d
10 characters wide on right %-10d
-floating point formatter
System.out.println("Total value is : %f \n" , 5.6);
- display 5.64 only and round off
- Note this rounds off System.out.println("Total value is : %.2f \n" , 5.634534534);
10 here means how many characters to use before decimal point -This will create extra space -Put - to have left align System.out.println("Total value is : %.2f \n" , 5.634534534);