How to reduce the load on the program even a little when combining characters with JAVA

When combining letters

Generate SQL WHERE statements in Java, You can create a character string from the acquired data, and you often use it.

What to do

How to get rid of when combining strings I think you've seen such a source. ..

code String str = "Ah ah"; str + = "good"; str + = "Uuu"; str + = "Yes"; ・ ・ ・ With this method, a new character string object is created every time, so it seems that the program load is applied without knowing it.

Let's use the StringBuffer type!

With this method, the object needs to be created only once, so it seems that the load on the program can be reduced.

code StringBuffer sb = new StringBuffer(); sb.append ("ah oh"); sb.append ("good"); sb.append ("Uuu"); sb.append ("yeah"); String str = str.toString();

Reference URL http://qiita.com/lrf141/items/f2fc30214a26dd6ba0b7

PS: For single threads, StringBuilder seems to be better.

Reference URL http://zudoh.com/archives/429

Recommended Posts

How to reduce the load on the program even a little when combining characters with JAVA
How to deal with the type that I thought about writing a Java program for 2 years
Hanashi stumbled a little on path trying to study Java with VScode
[Java] How to use Thread.sleep to pause the program
Until you run a Java program with the AWS SDK local to Windows
[Rails] When transitioning to a page with link_to, move to the specified location on the page
[Java] How to start a new line with StringBuilder
How to save a file with the specified extension under the directory specified in Java to the list
Summary of how to use the proxy set in IE when connecting with Java
How to take a screenshot with the Android Studio emulator
Java program to resize a photo into a square with margins
How to deploy a simple Java Servlet app on Heroku
How to deploy a kotlin (java) app on AWS fargate
Even in Java, I want to output true with a == 1 && a == 2 && a == 3
I want to return a type different from the input element with Java8 StreamAPI reduce ()
About the behavior when doing a file map with java
How to switch Java in the OpenJDK era on Mac
[Java] How to search for a value in an array (or list) with the contains method
How to execute Postgresql copy command with column information on Java
Logic to draw a circle with ASCII art on the console
How to switch Java version with direnv in terminal on Mac
Connecting to a database with Java (Part 1) Maybe the basic method
Replace with a value according to the match with a Java regular expression
[Rails] How to put a crown mark on the ranking function
Display user-defined characters on the I2C 1602 LCD with Raspberry Pi 3 & Java
How to write when installing Amazon Corretto 8 on CentOS 8 with Ansible.
How to solve the unknown error when using slf4j in Java
How to call with One Touch (without confirmation) on Android (Java)
How to build a little tricky with dynamic SQL query generation
[Java] How to update Java on Windows
How to make a Java container
[Java] How to create a folder
How to make a Java array
The first thing to do when you want to be happy with Heroku on GitHub with Eclipse in Java
How to interact with a server that does not crash the app
[Personal memo] How to interact with a random number generator in Java
[Java] How to retrieve the parameters passed from html on the server side
How to check before sending a message to the server with Spring Integration
[Java] How to turn a two-dimensional array with an extended for statement
Even in Java, I want to output true with a == 1 && a == 2 && a == 3 (PowerMockito edition)
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Ruby on Rails DB Tips for creating methods to reduce the load
[Docker] How to build when the source code is bind-mounted on the container
How to find out the Java version of a compiled class file
[Java small story] Monitor when a value is added to the List
[Java] How to get to the front of a specific string using the String class
How to find the total number of pages when paging in Java
How to pass a proxy when throwing REST over SSL in Java
How to get the absolute path of a directory running in Java
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
How to track when a bucket managed by scoop changes (mainly Java)
How to make an app with a plugin mechanism [C # and Java]
How to reference a column when overriding the column name method in ActiveRecord
How to check Java installed on Mac
[Java] How to use the File class
How to compile Java with VsCode & Ant
[Java] How to use the hasNext function
[Java] How to compare with equals method
[Java] How to use the HashMap class
[Java] How to use the toString () method
Studying how to use the constructor (java)