A memo of Java strings used in business. I used it during development, so I summarized it.
StringBuilder
StringBuilder class can be used after instantiation This is a class for performing character string operations.
In string concatenation, use the append method and the string you want to concatenate using the arguments.
When concatenating a large number of strings, you should try to use StringBuilder, which has the highest performance.
//Excerpt from some of the formats used in business
//Instance generation
StringBuilder sb = new StringBuilder();
//SQL generation
sb.append("SELECT");
sb.append("Sample");
sb.append("Sample2");
sb.append("Sample3");
sb.append("FROM");
sb.append("SampleTable");
//* Batch processing is performed 24 hours a day, 365 days a year, so it is used so that the processing speed does not slow down.
When using threads, StringBuilder may cause problems. Instead, use the StringBuffer class.
I don't want to use StringBuilder in a multithreaded environment, so StringBuilder with good performance if thread safety is guaranteed. If thread safety is not guaranteed, use StringBuffer instead.
The basic writing style is almost the same.
Many of the seniors in the company have been using Java for about 20 years in business, so I think that I am very fortunate because there are many people like mentors close to me as a Java beginner.
Recommended Posts