[Java] Java string

1 minute read

[Java string]

It is a memo of a Java character string used in business. I have summarized it because it is used during development.

StringBuilder

StringBuilder class can be used after instantiating It is a class for performing string operations.

For character string combination, use the character string you want to combine using the append method and argument.

When concatenating a large number of strings, you should try to use the StringBuilder that has the highest performance.

//Excerpt of part of the format used in the business

// Instantiation
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 the processing speed is not slowed down.

When using StringBuffer

When using threads, problems may occur with StringBuilder. Instead, use the StringBuffer class.

I don’t want to use StringBuilder in a multithreaded environment, so A StringBuilder with good performance if it is guaranteed to be thread-safe. If thread safety is not guaranteed, use StringBuffer instead.

The basic writing method is almost the same.

Digression

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.