How to optimize string creation?

By using string literals.

Ex:

File: StringPerformance .java

Output:

Time taken to create literal String : 9 ms
Time taken to create Object String : 11 ms

Hence, String creation using literals take less time.