Java Challenge #1: String Pool

Every time we create a different String, an object is created in the pool. How many objects were created in this situation?

Try to solve this challenge before seeing the answer below.


Answer: 3 Strings and 1 StringBuilder are created in the concatenation. For performance reasons, the JVM creates a pool of Strings. When a String with the same value is created, the JVM does not create another object in the pool.

Java Challenge #1: String Pool

One thought on “Java Challenge #1: String Pool

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s