What do you use when converting to String?

Isn't there a lot of time to change to String?

A lot? Especially the Primary Key I think there are many ints and longs When API communication is sandwiched, it will become a String

So the conversion is String.valueOf or ʻObject.toString`?

package test;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * test
 *
 * @author me
 *
 */
public class Test1 {

	/**
	 * main
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("-------Start measurement-------");
		Long start1 = System.currentTimeMillis();
		run1();
		Long end1 = System.currentTimeMillis();
		System.out.println("String.valueOf() : " + (end1 - start1) + "ms");
		Long start2 = System.currentTimeMillis();
		run2();
		Long end2 = System.currentTimeMillis();
		System.out.println("Object.toString() : " + (end2 - start2) + "ms");
		System.out.println("-------End of measurement-------");
	}

	/**
	 * {@link String#valueOf()}
	 */
	private static void run1() {
		IntStream.range(0, 5000000).boxed().map(String::valueOf).collect(Collectors.toList());
	}
	/**
	 * {@link Object#toString()}
	 */
	private static void run2() {
		IntStream.range(0, 5000000).boxed().map(Object::toString).collect(Collectors.toList());
	}

}

-------Start measurement-------
String.valueOf() : 2024ms
Object.toString() : 904ms
-------End of measurement-------

Yeah, that's different ...

Well, ʻObject.toString` can't be used for primitive types, and it feels like ...

By the way

package test;

import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * test
 *
 * @author me
 *
 */
public class TestT {

	/**
	 * main
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("-------Start measurement-------");
		Long start1 = System.currentTimeMillis();
		run1();
		Long end1 = System.currentTimeMillis();
		System.out.println((end1 - start1) + "ms");
		System.out.println("-------End of measurement-------");
	}

	/**
	 *Is this good?
	 */
	private static void run1() {
		IntStream.range(0, 5000000).boxed().map(v -> v + "").collect(Collectors.toList());
	}

}
-------Start measurement-------
3021ms
-------End of measurement-------

It's no good w

Recommended Posts

What do you use when converting to String?
What to do when javax.batch.operations.JobStartException occurs
What to do when you launch an application with rails
What to do if you can't use the rails command
What to do when a javax.el.PropertyNotWritableException occurs
What to do if you install Ubuntu
What to do when undefined method ʻuser_signed_in?'
What to do when you become a Problem During Content Assist
What to do when you run into a docker-compose node_modules problem
When you want to use the method outside
What to do if you push incorrect information
What to do when debugging "Source not found"
What to do when IllegalStateException occurs in PlayFramework
What to do if you get an error when you hit Heroku logs
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
<f: ajax> Unable to attach <f: ajax> to non-ClientBehaviorHolder What to do when you become a parent
What to do when The SSL certificate has expired
What to do when JSF tags do not become HTML
What to do if ClassNotFoundException occurs when starting Tomcat
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
ParseException: What to do when Unparseable date is reached
A memo to check when you try to use Lombok
How to use String [] args
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do when Address already in use is displayed after executing rails s
What to do if you get a port error when docker-compose up on Mac
What to do when it becomes Unable to find CDI BeanManager.
What to do if you get a java.io.IOException in GlassFish
What to do when Method not found in f: ajax
What to do when Cannot apply expression operators to method binding
Delegate is convenient to use when you want to reuse parts
[Rails Tutorial Chapter 2] What to do when you make a mistake in the column name
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
What to do after Vagrant install
When will you do the refactoring?
Do you use Stream in Java?
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What to do if you get a gcc error in Docker
[Rails] What to do when rails s does not respond or does not stop
What to do if you get a DISPLAY error in gym.render ()
The first thing to do before you can use Rails6 Ajax
java.security.InvalidKeyException: What to do when Illegal key size or default parameters
What to do if you get angry with OpenSSL with pyenv install
What to do if you forget the root password in CentOS7
Practice to use when you want to execute different processing groups serially
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
What to do when you want to know the source position where the method is defined in binding.pry
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do if you get "Changes not staged for commit:" when you git status after git add.
[IOS] What to do when the image is filled with one color
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you get an error during rails db: reset
What to do when CentOS cannot be started with VirtualBox on Catalina
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do when "npm ERR! Code ENOSELF" is displayed after npm install
What to do after updating Dockerfile, docker-compose.yml
[Android Studio] What to try when you get into error spitting hell