Tutorial

What is Java String Pool?

Published on August 3, 2022
author

Pankaj

What is Java String Pool?

As the name suggests, String Pool in java is a pool of Strings stored in Java Heap Memory. We know that String is a special class in java and we can create String objects using a new operator as well as providing values in double-quotes.

String Pool in Java

Here is a diagram that clearly explains how String Pool is maintained in java heap space and what happens when we use different ways to create Strings. String Pool in Java, string pool, java string pool String Pool is possible only because String is immutable in Java and its implementation of String interning concept. String pool is also example of Flyweight design pattern. String pool helps in saving a lot of space for Java Runtime although it takes more time to create the String. When we use double quotes to create a String, it first looks for String with the same value in the String pool, if found it just returns the reference else it creates a new String in the pool and then returns the reference. However using new operator, we force String class to create a new String object in heap space. We can use intern() method to put it into the pool or refer to another String object from the string pool having the same value. Here is the java program for the String Pool image:

package com.journaldev.util;

public class StringPool {

    /**
     * Java String Pool example
     * @param args
     */
    public static void main(String[] args) {
        String s1 = "Cat";
        String s2 = "Cat";
        String s3 = new String("Cat");
        
        System.out.println("s1 == s2 :"+(s1==s2));
        System.out.println("s1 == s3 :"+(s1==s3));
    }

}

Output of the above program is:

s1 == s2 :true
s1 == s3 :false

Recommended Read: Java String Class

How many Strings are getting Created in the String Pool?

Sometimes in java interview, you will be asked a question around String pool. For example, how many strings are getting created in the below statement;

String str = new String("Cat");

In the above statement, either 1 or 2 string will be created. If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. If there is no string literal “Cat” in the pool, then it will be first created in the pool and then in the heap space, so a total of 2 string objects will be created. Read: Java String Interview Questions

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

Category:
Tutorial
Tags:

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
March 18, 2013

hi … excellent post … one correction - “we force String class to create a new String object and then place it in the pool.” here, new operator creates object in Java heap, not in pool.

- abhay agarwal

JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
April 14, 2013

String Pool only contains reference to the String objects. The text means the same thing.

- Pankaj

JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
December 3, 2014

Hi Pankaj, so do you mean that String pool only contains reference to string but not actual value/string ?

- Abhi

    JournalDev
    DigitalOcean Employee
    DigitalOcean Employee badge
    March 31, 2015

    You are contradicting yourself here. First you said String objects live in the pool, now you say only the references do. So where do the objects (values) they reference to live ? In your image you have the actual values inside the pool.

    - rojaja

      JournalDev
      DigitalOcean Employee
      DigitalOcean Employee badge
      September 20, 2013

      Yes, Pankaj. Please update this post accordingly. Your other posts also say so.

      - Rishi Raj

        JournalDev
        DigitalOcean Employee
        DigitalOcean Employee badge
        September 1, 2013

        Where the string stored.Means location of string where it stored.

        - Ridham Shah

          JournalDev
          DigitalOcean Employee
          DigitalOcean Employee badge
          October 9, 2013

          Could you post some example on intern() method.

          - siddu

            JournalDev
            DigitalOcean Employee
            DigitalOcean Employee badge
            January 4, 2014

            I have one confusion, when we create a new String Object like String s = new String (“abc”); As far as I know, this will create a new String Object in Heap and also abc will go in String constant pool and s will point value exists in string constant pool… which means the value already exists in String Constant Pool, so what will intern do in this case? Also String Constant Pool is not a part of Java Heap Memory…?

            - kunal

            JournalDev
            DigitalOcean Employee
            DigitalOcean Employee badge
            January 6, 2014

            When we use new keyword to create the String object, it doesn’t go into the String Pool. When we call intern method, then it checks if any String with same value is already present in the pool or not. If there is already a String with same value, it returns the reference or else it places the String into the pool.

            - Pankaj

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              April 7, 2014

              Hi Kunal, you can refer below snippet String str1 = “abc”; String str2 = “ab”; String str3 = “c”; String str4 = str2 + str3;//using StringBuilder for concatenation and returns new String object System.out.println(str1 == str4); // returns false str4 = str4.intern(); System.out.println(str1 == str4); // returns true

              - Ganesh Rashinker

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              May 31, 2014

              Hi Ganesh, I have two questions :- 1) Why the below line is returning false, It should return true because when str4 will create than first it will check in string pool whether any other string value is present or not with the same value. If str1 is already there with the same value than it should refer the same reference as str1 has. System.out.println(str1 == str4); // returns false 2) In your above example “intern” method you are using for string pool as str4.intern(). Can we use “intern” method for string pool also?

              - Mahrshi

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              August 19, 2014

              I am also having the same doubt # 1. Somebody please reply who knows the correct answer?

              - johny

              JournalDev
              DigitalOcean Employee
              DigitalOcean Employee badge
              November 3, 2014

              string concatenation(using + operator) is same as creating new String object fr eg:- String s1=“abc”; String s2=“def”; String s3=s1+s2; // It is same as String s3 = new String(“abcdef”);

              - balinder

                JournalDev
                DigitalOcean Employee
                DigitalOcean Employee badge
                February 20, 2015

                in frist question You are Right. when we create String by new keyword then one will go to heap and another in String pool String constant pool is depend on the JVM. architecture

                - vinod

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  April 4, 2014

                  How come String Pool has two Cat literals and is Stringpool a part of Heap?

                  - Ganesh

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  April 4, 2014

                  Corrected the image, yes String Pool is part of Java Heap memory.

                  - Pankaj

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  April 7, 2014

                  String str1 = “abc”;//reference is checked on constant pool String str2 = new String(“abc”);//reference is checked on heap System.out.println(str1 == str2);//returns false //that is why we use intern str2 = str2.intern(); System.out.println(str1 == str2);//return true as both are pointing to string pool //String pool is a part of constant pool and memory is getting allocated in Method Area whereas when we use new operator memory is getting allocated in heap. //Note: Methos area can be a part of heap or a seperate memory area. this depends on JVM implementation.

                  - Ganesh Rashinker

                  JournalDev
                  DigitalOcean Employee
                  DigitalOcean Employee badge
                  April 9, 2014

                  Please check this blog for a demo of what I have mentioned above. Please correct me if my understanding is wrong somewhere. https://ganeshrashinker.blogspot.in/

                  - Ganesh Rashinker

                    JournalDev
                    DigitalOcean Employee
                    DigitalOcean Employee badge
                    August 13, 2014

                    String s = “ashish”; String b = new String(“ashish”); b.intern(); System.out.println(s==b); if string pool is manged then why not string ‘s’ reference is returned on b.intern() to b. It is printing false which means their reference are not same.

                    - Ashish

                    JournalDev
                    DigitalOcean Employee
                    DigitalOcean Employee badge
                    August 13, 2014

                    You need to write b = b.intern();, see you haven’t updated the reference of “b” variable.

                    - Pankaj

                      JournalDev
                      DigitalOcean Employee
                      DigitalOcean Employee badge
                      February 20, 2015

                      intern() method return a String . but in case of you does not hold return of intern ().

                      - vinod

                        JournalDev
                        DigitalOcean Employee
                        DigitalOcean Employee badge
                        September 11, 2014

                        If for example: String str1 = “abc”; String str2 = new String(“def”); Then, Case 1: String str3 = str1.concat(str2) will go in the heap or pool? Case 2: String str4 = str2.concat(“HI”) will go in the heap or pool?

                        - krishna

                        JournalDev
                        DigitalOcean Employee
                        DigitalOcean Employee badge
                        November 11, 2014

                        will be creating the new object in the string pool,

                        - krishna

                        JournalDev
                        DigitalOcean Employee
                        DigitalOcean Employee badge
                        October 18, 2016

                        If it is creating in the pool, then the following code should output “True”. But it is not? String str1 = “abc”; str1 = str1.concat(“d”); if(str1 == “abcd”) System.out.println(“True”);

                        - Maaniccka Poonkundran

                        JournalDev
                        DigitalOcean Employee
                        DigitalOcean Employee badge
                        July 12, 2018

                        try this String str1 = “abc”; str1 = str1.concat(“d”).intern(); if(str1 == “abcd”) System.out.println(“true”); the object are not placed in pool automatically, unless intern is called. so when you call intern above “abcd” is placed in pool and when it program encounters the literal “abcd” it finds it in the pool and hence the references are equal

                        - Alok Chandna

                          JournalDev
                          DigitalOcean Employee
                          DigitalOcean Employee badge
                          October 4, 2014

                          public class MainDemo { public void comp() { String s1=“India”; String s2=“India”; String s3=new String(“India”); System.out.println(“== result:” + s1==s2); // false System.out.println(“equals result:” + s1.equals(s2)); // true System.out.println(“****************”); System.out.println(“== result:” + s1==s3); // false System.out.println(“equals result:” + s1.equals(s3)); // true } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub MainDemo obj=new MainDemo(); obj.comp(); } } Question - what is the difference between s1==s2 and s1==s3 , => both returns same result. but in your post s1==s2 is true that is not right result. I have checked this by writing same program in to this post. So plz clear my doubt ??

                          - sanjaya verma

                          JournalDev
                          DigitalOcean Employee
                          DigitalOcean Employee badge
                          October 4, 2014

                          “== result:” + s1==s2 + operator priority is more, so it will result in "== result:India"=="India" and hence false. I hope it will clear your confusion.

                          - Pankaj

                          JournalDev
                          DigitalOcean Employee
                          DigitalOcean Employee badge
                          November 3, 2014

                          to get the desired result you can write: System.out.println(“== result:” + (s1==s2) );

                          - balinder

                            JournalDev
                            DigitalOcean Employee
                            DigitalOcean Employee badge
                            November 3, 2014

                            Thnx for the post. helped to clarify a lot of things

                            - balinder

                              JournalDev
                              DigitalOcean Employee
                              DigitalOcean Employee badge
                              November 4, 2014

                              In the name of god. public static void main(String[] args) { String s1 = “Cat”; String s2 = “Cat”; String s3 = new String(“Cat”); String test; System.out.println(“s1 == s2 :”+(s1==s2)); System.out.println(“s1 == s3 :”+(s1==s3)); } hi, how to return value(No address) from heap(s3) to stack(test). Thanks.

                              - Amir hossein

                                JournalDev
                                DigitalOcean Employee
                                DigitalOcean Employee badge
                                December 30, 2014

                                package com.journaldev.util; public class StringPool { /** * Java String Pool example * @param args */ public static void main(String[] args) { String s1 = “Cat”; String s2 = “Cat”; // here s1 & s2 value Cat stored into String Constant pool only once, so no doubt. String s3 = new String(“Cat”); String s4 = new String(“Cat”) ; // my question is here. here s3 & s4 value Cat is two times created into normal pool or only once created into normal pool. System.out.println(“s1 == s2 :”+(s1==s2)); System.out.println(“s1 == s3 :”+(s1==s3)); System.out.println(“s3 == s4 :”+(s3==s4)); // here both value of hashCode same but why to be false? } }

                                - Karuppasamy

                                JournalDev
                                DigitalOcean Employee
                                DigitalOcean Employee badge
                                December 30, 2014

                                s3 and s4 will be referencing to two different objects. == checks if reference is same, that’s why s3==s4 is false.

                                - Pankaj

                                JournalDev
                                DigitalOcean Employee
                                DigitalOcean Employee badge
                                March 18, 2015

                                s3 == s4 will return true, have you try it? I have, it is true even I think it should not

                                - xiaocai607

                                JournalDev
                                DigitalOcean Employee
                                DigitalOcean Employee badge
                                March 18, 2015

                                Please ignore my comments

                                - xiaocai607

                                  JournalDev
                                  DigitalOcean Employee
                                  DigitalOcean Employee badge
                                  April 18, 2016

                                  If s1 & s3 “Cat” objects are created in Heap & SCP area respectively and (s1==s3) returning false that is correct but why their hascodes are same then? If hashcodes are same means both references are pointing to same object then (s1==s3) should have returned true ideally? Please clarify on this. public static void main(String[] args) { String s1 = new String(“Cat”); String s3 = “Cat”; System.out.println(s1.hashCode() + " && " + s3.hashCode()); } O/P : 67510 && 67510 Regards, Vishal

                                  - Vishal Nikam

                                  JournalDev
                                  DigitalOcean Employee
                                  DigitalOcean Employee badge
                                  April 18, 2016

                                  hashcode has nothing to do with object reference.

                                  - Pankaj

                                    JournalDev
                                    DigitalOcean Employee
                                    DigitalOcean Employee badge
                                    May 18, 2016

                                    check with System.identityHashCode(s1); System.identityHashCode(s3); it will help u

                                    - Biswa

                                      JournalDev
                                      DigitalOcean Employee
                                      DigitalOcean Employee badge
                                      February 12, 2015

                                      Pankaj, Is there any way to get the size of String Pool?

                                      - Pradeep Singh

                                        JournalDev
                                        DigitalOcean Employee
                                        DigitalOcean Employee badge
                                        February 19, 2015

                                        String s=“abc”; s = s+“def”; System.out.println("String Result:- "+s);//output - String Result:- abcdef In this case content of ‘s’ variable is getting changed but according to java concept String is immutable. So,can you please explain me what happen with ‘s’ variable in the string pool?

                                        - Pranita W

                                        JournalDev
                                        DigitalOcean Employee
                                        DigitalOcean Employee badge
                                        March 6, 2015

                                        When you write String s=“abc” at this point s refers to string whose value is “abc”. When you write s=s+“def” a new string “abcdef” is created and s now refers to this new string and not to “abc”. Hence originally created “abc” string remains unchanged. It remains as it is in pool.Hence strings are called immutable.

                                        - Sarika

                                          JournalDev
                                          DigitalOcean Employee
                                          DigitalOcean Employee badge
                                          March 4, 2015

                                          Thanks. But reply form is too far from article. I can forget my answer during scrolling down )

                                          - Timofei

                                          JournalDev
                                          DigitalOcean Employee
                                          DigitalOcean Employee badge
                                          March 5, 2015

                                          Reply form after comments, so that people can read others comments first. Chances are you will find your queries answered in some of the comments, saves time.

                                          - Pankaj

                                            JournalDev
                                            DigitalOcean Employee
                                            DigitalOcean Employee badge
                                            March 31, 2015

                                            Timofei, ever heard of Ctrl+End ? It will take you directly to the end of the page

                                            - rojaja

                                              JournalDev
                                              DigitalOcean Employee
                                              DigitalOcean Employee badge
                                              March 30, 2015

                                              Hi , Can you please clarify me, how many objects will be created in below case and why? String s1=“cat”; String s2=“cat”; String s3=“c”+ “at”; String s4= new String(“cat”); String s5=“kitty” + “cat”; String s6= new String(kittycat); Thanks In Advance. :)

                                              - Satish

                                              JournalDev
                                              DigitalOcean Employee
                                              DigitalOcean Employee badge
                                              March 11, 2016

                                              4

                                              - saroj

                                                JournalDev
                                                DigitalOcean Employee
                                                DigitalOcean Employee badge
                                                May 18, 2016

                                                7 objects 1.”cat” 2.”c” 3.“at” 4.new String(“cat”); 5."kitty” 6.“kittycat” 7.new String(kittycat)

                                                - Biswajit sahoo

                                                  JournalDev
                                                  DigitalOcean Employee
                                                  DigitalOcean Employee badge
                                                  April 2, 2015

                                                  Hi Pankaj, I am following you articles and finding it really precise. Really appreciate your efforts. But coming to this article, I have one doubts. The value in the String pool are “String” or reference to the String Object created in the Heap i.e. collection of references to String objects ?

                                                  - Ravi

                                                  JournalDev
                                                  DigitalOcean Employee
                                                  DigitalOcean Employee badge
                                                  April 2, 2015

                                                  String Pool contains String objects, remember that ‘reference’ variables always part of Stack memory, so obviously it can’t be in string pool that is part of heap memory.

                                                  - Pankaj

                                                  JournalDev
                                                  DigitalOcean Employee
                                                  DigitalOcean Employee badge
                                                  April 2, 2015

                                                  Hi Pankaj, I am understanding your point and agree to that. But after going throw a question on Stackoverflow , I am confused … “Is String Literal Pool a collection of references to the String Object, Or a collection of Objects” https://stackoverflow.com/questions/11700320/is-string-literal-pool-a-collection-of-references-to-the-string-object-or-a-col that is taken from https://www.javaranch.com/journal/200409/Journal200409.jsp#a1 If possible, kindly have a look once and confirm from your end. Thank you.

                                                  - Ravi

                                                    JournalDev
                                                    DigitalOcean Employee
                                                    DigitalOcean Employee badge
                                                    April 3, 2015

                                                    Hi pankaj, Can you please clarify me, how many objects will be created in below case and why?am slightly confused in this. String s1=”cat”; String s2=”cat”; String s3=”c”+ “at”; String s4= new String(“cat”); String s5=”kitty” + “cat”; String s6= new String(“kittycat”); String s7=s5; Thanks In Advance. :)

                                                    - satish

                                                    JournalDev
                                                    DigitalOcean Employee
                                                    DigitalOcean Employee badge
                                                    May 26, 2015

                                                    Short Answer: 4 objects. Explanation below: String s1=”cat”; //1st object created in String Pool and s1 started referring to it String s2=”cat”; //s2 refers to the same String whom s1 refers to String s3=”c”+ “at”; //s3 refers to the same String whom s1 and s2 are referring String s4= new String(“cat”); //A new object (2nd) is created in Heap and s4 refers to it String s5=”kitty” + “cat”; //A new object (3rd) is created in string pool and s5 refers to it String s6= new String(“kittycat”); //A new object (4th) is created in heap and s6 refers to it String s7=s5; //s7 refers to same string whom s5 refers.

                                                    - Parvinder Singh

                                                      JournalDev
                                                      DigitalOcean Employee
                                                      DigitalOcean Employee badge
                                                      February 2, 2016

                                                      This is so interesting. My first program was creating rows that contained 3 types of datapointers. Row = new(Prow ) >> First Row instantiated; Pointer Row in the STACK refering to it . But then the second row: ThisRow = Row; ThisRow^.next = new(Prow) >> Now I am instantiating by pointer ‘next’ which is part of object (1st row) that exists in the HEAP, but was already defined in object. Instantiating 100 times, using ref. called ‘next’, you go deeper and deeper in the heap. Can you still say ref. variables are always stack variables?

                                                      - Pete de Fina

                                                        JournalDev
                                                        DigitalOcean Employee
                                                        DigitalOcean Employee badge
                                                        April 25, 2017

                                                        So, after the method execution is over, all local String references will be nullified and the objects in the heap will be garbage collected. is it?

                                                        - Anushree

                                                          JournalDev
                                                          DigitalOcean Employee
                                                          DigitalOcean Employee badge
                                                          April 3, 2015

                                                          Nice explanation Pankaj…

                                                          - Dhananjay

                                                            JournalDev
                                                            DigitalOcean Employee
                                                            DigitalOcean Employee badge
                                                            July 12, 2015

                                                            Hi, I have one example which I found a little confusing. I understand that in context of String object type, by using NEW word, new object is created and when using “” in String initialization, String pool mechanizm is used. Why isn’t String pool used in following case? *******************         String myStr = “good”;        char[] myCharArr = {‘g’, ‘o’, ‘o’, ‘d’ };         String newStr = “”;         for(char ch : myCharArr){             newStr = newStr + ch;          }         boolean b1 = newStr == myStr;          boolean b2 = newStr.equals(myStr);                   System.out.println(b1+ " " + b2); (false true is printed) ******************* Thx in advance, Teodor

                                                            - Teo

                                                            JournalDev
                                                            DigitalOcean Employee
                                                            DigitalOcean Employee badge
                                                            September 2, 2015

                                                            Dear Ravi, This is where “==” and .equals differ. “==” checks equality for hash code of objects reference while .equals compares their contents. Pls let me know if u have any confusion.

                                                            - varun

                                                            JournalDev
                                                            DigitalOcean Employee
                                                            DigitalOcean Employee badge
                                                            May 14, 2016

                                                            String s1=“Hello”; String s2=“Java”; String s3=“Hello Java”; String s4=s1+" "+s2; String s5=new(“Hello Java”); System.out.println(s3==s4);// false! understood. System.out.println(s3.hashCode()==s4.hashCode()); true how? System.out.println(s3.hashCode()==s5.hashCode()); true how?

                                                            - Anupam

                                                            JournalDev
                                                            DigitalOcean Employee
                                                            DigitalOcean Employee badge
                                                            November 20, 2020

                                                            hashcode is calculated always same for the same value of string , you can check the implementation of hashcode() in String. hence it gives same value. its not calculated based on their reference location whether its on heap or scp.

                                                            - vipul potdar

                                                              JournalDev
                                                              DigitalOcean Employee
                                                              DigitalOcean Employee badge
                                                              September 17, 2015

                                                              You used the String equal() with a char[] array. char[] arrays are Object not String. This “newStr.equals(myStr)” compares a String with an array. When comparing 2 objects for “Equal” they should be of the same class. The equal method takes an Object but the methods usually make an instanceof check, cast to a specific type then compare the “this” with the “argument”. The rule of tumb for equal on the Java objects is: instanceof, cast then compare object internals. Of course you can implement any freaky equal but in general you should stick to the “contract” if you would have done: newStr.equals(new String(myStr)) it would have worked because it makes a new String object out of the array and the object passed to the method is a String in this case.

                                                              - Adrian

                                                                JournalDev
                                                                DigitalOcean Employee
                                                                DigitalOcean Employee badge
                                                                March 8, 2016

                                                                Hi Teo, If concatenate variable, so here hashcode always will be different. newStr, ch is variable. You must need to concatenate direct literal only, instead of variable means… newStr = ‘g’+“ood”; result would be ‘true’. ‘g’ and “ood” is literal. I think it not possible in loop.

                                                                - Deepak

                                                                  JournalDev
                                                                  DigitalOcean Employee
                                                                  DigitalOcean Employee badge
                                                                  September 2, 2015

                                                                  String s=“abc” ;-----creates a string object “abc” with reference ‘s’ in string pool. String s=new String(“abc”);----creates a string object “abc” with reference ‘s’ in heap memory and also creates a string object “abc” in string pool without reference so here two objects are created then what is the necessity for creating String object using new operator?

                                                                  - muni

                                                                  JournalDev
                                                                  DigitalOcean Employee
                                                                  DigitalOcean Employee badge
                                                                  January 14, 2016

                                                                  Good question. Anyone have explanation?

                                                                  - Anjani

                                                                  JournalDev
                                                                  DigitalOcean Employee
                                                                  DigitalOcean Employee badge
                                                                  July 3, 2016

                                                                  public class Hash { public static void main(String[] args) { String s1=“cat”; String s2=“cat”; // Both String hashcode will be same if String content is same System.out.println(s1.hashCode()); System.out.println(s2.hashCode()); // After changing content of s1 String hashcode will changed s1=“dog”; System.out.println(s1.hashCode()); System.out.println(s2.hashCode()); } }

                                                                  - Sabi

                                                                  JournalDev
                                                                  DigitalOcean Employee
                                                                  DigitalOcean Employee badge
                                                                  July 27, 2016

                                                                  here String literal created new object and pointing to s1 reference variable then new hashCode created…

                                                                  - shailendra tiwari

                                                                    JournalDev
                                                                    DigitalOcean Employee
                                                                    DigitalOcean Employee badge
                                                                    March 11, 2016

                                                                    it creates a reference in pool for feature used.

                                                                    - saroj

                                                                      JournalDev
                                                                      DigitalOcean Employee
                                                                      DigitalOcean Employee badge
                                                                      October 7, 2016

                                                                      String s=new String(“abc”);—-creates a string object “abc” with reference ‘s’ only in heap memory and not in string pool.

                                                                      - Ajinkya Rane

                                                                        JournalDev
                                                                        DigitalOcean Employee
                                                                        DigitalOcean Employee badge
                                                                        September 17, 2015

                                                                        Another thing about the Java String Pool. For long term maintenance of your code you should use the “equals” method not the “==”. You may refactor the code and string pool object is replaced with a heap object and you get all kinds of problems. Refactor tools don’t “see” the cases where == should be changed to equal. primitive => == objects => equals

                                                                        - Adrian

                                                                          JournalDev
                                                                          DigitalOcean Employee
                                                                          DigitalOcean Employee badge
                                                                          September 18, 2015

                                                                          great pictrue

                                                                          - shellbye

                                                                            JournalDev
                                                                            DigitalOcean Employee
                                                                            DigitalOcean Employee badge
                                                                            March 6, 2016

                                                                            Does String pool has divided into parts like constant pool and non-constant pool?

                                                                            - Manjunath

                                                                              JournalDev
                                                                              DigitalOcean Employee
                                                                              DigitalOcean Employee badge
                                                                              April 29, 2016

                                                                              class ClassM2{ public static void main(String[] args){ String s2 = “test”; String s3 = “test”; String s4 = s3+“”; System.out.println(s2==s3); System.out.println(s3==s4); } } Why s3==s4 gives “false”? I know “test” string stores in String pool and s2 & s3 points to same reference. but why not s4? It also has value “test”. Please explain.

                                                                              - Hiren Mistry

                                                                              JournalDev
                                                                              DigitalOcean Employee
                                                                              DigitalOcean Employee badge
                                                                              April 29, 2016

                                                                              Because s4 is not created in Pool since Compiler puts string values in pool that are constant right from compile time. s4 value is dependent on s3 variable at runtime, hence it’s created in heap. Refer https://stackoverflow.com/questions/16729045/behavior-of-string-literals-is-confusing

                                                                              - Pankaj

                                                                              JournalDev
                                                                              DigitalOcean Employee
                                                                              DigitalOcean Employee badge
                                                                              June 9, 2016

                                                                              Awesome explation Pankaj… Thanks :)

                                                                              - Prashant

                                                                                JournalDev
                                                                                DigitalOcean Employee
                                                                                DigitalOcean Employee badge
                                                                                June 12, 2016

                                                                                question-Runtime constant pool and String pool are same thing or different ?

                                                                                - Prashant Gawande

                                                                                JournalDev
                                                                                DigitalOcean Employee
                                                                                DigitalOcean Employee badge
                                                                                June 12, 2016

                                                                                Constant Pool and String Pool are different. Refer https://stackoverflow.com/questions/23252767/string-pool-vs-constant-pool

                                                                                - Pankaj

                                                                                JournalDev
                                                                                DigitalOcean Employee
                                                                                DigitalOcean Employee badge
                                                                                June 17, 2016

                                                                                java doc says they are same

                                                                                - pravin

                                                                                  JournalDev
                                                                                  DigitalOcean Employee
                                                                                  DigitalOcean Employee badge
                                                                                  June 20, 2016

                                                                                  My idea is that if an object is in heap like this String s1=new String(“hello”); and let us say s1 holds address 123 then i do this, s1.intern(); still now s1 address 123 and holds the object “hello” in 123 However one more String object “hello” (literal object) has been created whose reference is lets say 321. Now this reference is being stored in the constant pool table. Am I correct?

                                                                                  - Mayank Bhandari

                                                                                  JournalDev
                                                                                  DigitalOcean Employee
                                                                                  DigitalOcean Employee badge
                                                                                  June 20, 2016

                                                                                  *String pool reference table, not constant pool table.

                                                                                  - Mayank Bhandari

                                                                                    JournalDev
                                                                                    DigitalOcean Employee
                                                                                    DigitalOcean Employee badge
                                                                                    August 26, 2016

                                                                                    I have trouble understanding your following statement: String str = new String(“Cat”); In above statement, either 1 or 2 string will be created. If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. If there is no string literal “Cat” in the pool, then it will be first created in the pool and then in the heap space, so total 2 string objects will be created. If you do not intern str how could a string literal be created in the string pool? If you do and the “Cat” literal does not already exists in the pool, it will only be created in the pool not on the heap. If you have something like this: String str = new String(“Cat”).intern(); then 0 or 1 string will be created depending on whether a “Cat” literal exists. Thanks, Jun

                                                                                    - Jun Zhuang

                                                                                      JournalDev
                                                                                      DigitalOcean Employee
                                                                                      DigitalOcean Employee badge
                                                                                      September 11, 2016

                                                                                      nice tutorials

                                                                                      - Deepak Kumar Sahu

                                                                                        JournalDev
                                                                                        DigitalOcean Employee
                                                                                        DigitalOcean Employee badge
                                                                                        September 15, 2016

                                                                                        Is string pool part of heap. I thought it was part of method area which is actually different from heap. The first diagram shows it as a part of heap above.

                                                                                        - Amol Aggarwal

                                                                                          JournalDev
                                                                                          DigitalOcean Employee
                                                                                          DigitalOcean Employee badge
                                                                                          October 15, 2016

                                                                                          When I create a String object with New operator and then use Intern() method, If String value not in Pool then add if exist in Pool then returned back reference. But what happens to the first memory created with New String(“test”)? (In Heap and outsize of Pool)

                                                                                          - Mohamad

                                                                                            JournalDev
                                                                                            DigitalOcean Employee
                                                                                            DigitalOcean Employee badge
                                                                                            October 29, 2016

                                                                                            hi pankaj, does StringBuffer also places object in string pool? StringBuffer sb=new StringBuffer(“abc”) how many objects are created with above line

                                                                                            - shravan

                                                                                            JournalDev
                                                                                            DigitalOcean Employee
                                                                                            DigitalOcean Employee badge
                                                                                            November 8, 2016

                                                                                            yes, it does. and it creates two objects.

                                                                                            - guest

                                                                                              JournalDev
                                                                                              DigitalOcean Employee
                                                                                              DigitalOcean Employee badge
                                                                                              November 26, 2016

                                                                                              hi pankaj, I Could not understand the following sentencecan’t undestand it . If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. why pool not heap? plz reply me thank you XD

                                                                                              - nbsaw

                                                                                                JournalDev
                                                                                                DigitalOcean Employee
                                                                                                DigitalOcean Employee badge
                                                                                                December 27, 2016

                                                                                                Hello, i have statement like as below please suggest hoe it will store in which memory, String s1 = “ABC”; String s2 = “ABC”; String s3 = s1; String s3 = new String(“ABC”); String s4 = s3;

                                                                                                - Mayur

                                                                                                JournalDev
                                                                                                DigitalOcean Employee
                                                                                                DigitalOcean Employee badge
                                                                                                May 22, 2017

                                                                                                Hi, You will get an Compile Time Exception declaring like this String s3 = s1; String s3 = new String(“ABC”);

                                                                                                - Shankara Nethran S N

                                                                                                  JournalDev
                                                                                                  DigitalOcean Employee
                                                                                                  DigitalOcean Employee badge
                                                                                                  December 31, 2016

                                                                                                  Hi Pankaj, String abc = “a” + “b” + “c”; Here how many objects created in string pool memory?

                                                                                                  - Mithun C T

                                                                                                  JournalDev
                                                                                                  DigitalOcean Employee
                                                                                                  DigitalOcean Employee badge
                                                                                                  January 4, 2017

                                                                                                  3

                                                                                                  - Nilesh

                                                                                                    JournalDev
                                                                                                    DigitalOcean Employee
                                                                                                    DigitalOcean Employee badge
                                                                                                    February 5, 2017

                                                                                                    One or zero. Java compiler will merge these three “a” “b” “c” strings into one “abc”. Then if string pool contains “abc” then none string will be created. Otherwise one string “abc” will be created.

                                                                                                    - Ryszard S

                                                                                                      JournalDev
                                                                                                      DigitalOcean Employee
                                                                                                      DigitalOcean Employee badge
                                                                                                      May 27, 2017

                                                                                                      It will create only one string in the SCP. It merges a,b,c and creates abc.If it is not already there in the pool

                                                                                                      - KK

                                                                                                        JournalDev
                                                                                                        DigitalOcean Employee
                                                                                                        DigitalOcean Employee badge
                                                                                                        February 28, 2017

                                                                                                        On interview I was asked to explain string pool. Unfortunately I did not know answer. Its reason why I read this post. Tnx!

                                                                                                        - Gerrix

                                                                                                          JournalDev
                                                                                                          DigitalOcean Employee
                                                                                                          DigitalOcean Employee badge
                                                                                                          March 14, 2017

                                                                                                          Very good example, Thanks for sharing.

                                                                                                          - Dinesh Krishnan

                                                                                                            JournalDev
                                                                                                            DigitalOcean Employee
                                                                                                            DigitalOcean Employee badge
                                                                                                            March 15, 2017

                                                                                                            String s1=new String(“abc”); Above line will create only one object in the heap, it won’t create two objects as you mentioned (one in heap and one in pool). To put the object in pool you need to call ‘intern()’ on this object, then it checks the pool for existence of this object in the pool, if not available then it will create one in the pool . Example : String s1=new String('abc").intern(); This will check the SCP for “abc” object, if not present then it will create this object and ‘s1’ reference will change to the SCP object and heap object will be dereferenced. Suppose if we change your code like this : String s1=new String(“abc”); s1.intern(); Then this will just create the “abc” object in SCP, but this object will not referred by the reference variable ‘s1’ (as it’s not assigned to ‘s1’). I hope it’s more clear now. Kindly comment if someone having different understanding on the same so that it will help to get correct information on the same. Kindly update the article w.r.t above details, otherwise it will give wrong impression to the reader.

                                                                                                            - Shidram Jyoti

                                                                                                            JournalDev
                                                                                                            DigitalOcean Employee
                                                                                                            DigitalOcean Employee badge
                                                                                                            April 13, 2017

                                                                                                            String s1=new String(“abc”); This above statement does create two objects. one in heap and another in String Constant pool. But the reference points to the heap object not to the one in the pool.

                                                                                                            - Sam

                                                                                                              JournalDev
                                                                                                              DigitalOcean Employee
                                                                                                              DigitalOcean Employee badge
                                                                                                              July 1, 2019

                                                                                                              Hi Shidram Jyoti, Is there any way to validate your point that only one object will be created? Because all of the articles over the net says that two different objects will be created. One in Heap and other in String Constant Pool.

                                                                                                              - Amit

                                                                                                                JournalDev
                                                                                                                DigitalOcean Employee
                                                                                                                DigitalOcean Employee badge
                                                                                                                September 17, 2019

                                                                                                                I think you explanation is correct. If We create String object using new it will create only one object. intern() method is use for create same heap object into constant pool.

                                                                                                                - Ravi Awasthi

                                                                                                                  JournalDev
                                                                                                                  DigitalOcean Employee
                                                                                                                  DigitalOcean Employee badge
                                                                                                                  May 30, 2017

                                                                                                                  String s1= “old value of s1”; s1=“new value of s1”; Sysout(s1); It will give new value. Is it possible to get old value as same reference to two different literals are there.

                                                                                                                  - Purushottam

                                                                                                                  JournalDev
                                                                                                                  DigitalOcean Employee
                                                                                                                  DigitalOcean Employee badge
                                                                                                                  August 24, 2017

                                                                                                                  Not possible because as you write s1=“new value of s1”, s1 will now start pointing to “new value of s1” and we now don’t have any reference to “old value of s1”. So “old value to s1” will be lost.

                                                                                                                  - Vinay Kumar

                                                                                                                    JournalDev
                                                                                                                    DigitalOcean Employee
                                                                                                                    DigitalOcean Employee badge
                                                                                                                    July 12, 2017

                                                                                                                    String s1 = “Hello”.concat(“World”); String s3 = new String(“HelloWorld”); //Line-2 String s2 = s1.intern(); System.out.println(s1 == s2); //false System.out.println(s1 == s3); //false System.out.println(s2 == s3); //false If I removed Line-2 and compare s1==s2, it will return true. Could anyone explain me what exactly happens in string pool after Line-2? Thanks

                                                                                                                    - salman

                                                                                                                    JournalDev
                                                                                                                    DigitalOcean Employee
                                                                                                                    DigitalOcean Employee badge
                                                                                                                    August 2, 2017

                                                                                                                    if you use jdk1.7 or later, it will output “true”, and if you use jdk1.6, it will output “false”. Because String’s member function intern() 's behavior is different. In jdk1.7, it will check if there is a same literal in string constant pool. if yes, it will return the reference of this literal object. otherwise it will store the reference of string object created by new operator into the string constant pool and then return this reference. In your code snippet, String s3 = new String(“HelloWorld”) this sentence will create string “Helloworld” in string constant pool, then String s2 = s1.intern(); s2 will refer to this string object, so System.out.println(s1 == s2); it will output “false”. when you remove the sentence in line2, there is not literal “Helloworld” in string constant pool, so String s2 = s1.intern(); it will return the reference of object in heap, so output is “true”

                                                                                                                    - ZT

                                                                                                                      JournalDev
                                                                                                                      DigitalOcean Employee
                                                                                                                      DigitalOcean Employee badge
                                                                                                                      March 26, 2019

                                                                                                                      String s1 = “Hello”.concat(“World”); This will create helloworld in pool as well as heap. Right ?

                                                                                                                      - Rahul Bawa

                                                                                                                        JournalDev
                                                                                                                        DigitalOcean Employee
                                                                                                                        DigitalOcean Employee badge
                                                                                                                        September 20, 2017

                                                                                                                        Hello Pankaj, Could you plea address below doubt? Lets say in my Java app I have one calss - A having method for String as setContent and getContent. Now Once I set the String Content using setter method, later I use that object of class A to get that String and put in List using getter method. where that list element will point ? to String pool or somewhere else?

                                                                                                                        - Tukaram

                                                                                                                        JournalDev
                                                                                                                        DigitalOcean Employee
                                                                                                                        DigitalOcean Employee badge
                                                                                                                        September 20, 2017

                                                                                                                        If you will use String literal, it will point to String Pool. If you use new operator, then heap.

                                                                                                                        - Pankaj

                                                                                                                          JournalDev
                                                                                                                          DigitalOcean Employee
                                                                                                                          DigitalOcean Employee badge
                                                                                                                          January 4, 2018

                                                                                                                          In above statement, either 1 or 2 string will be created. If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. will be created in pool or heap memory(outside pool)?

                                                                                                                          - Vettaiyan

                                                                                                                            JournalDev
                                                                                                                            DigitalOcean Employee
                                                                                                                            DigitalOcean Employee badge
                                                                                                                            November 26, 2016

                                                                                                                            hi pankaj, I Could not understand the following sentencecan’t undestand it . If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. why pool not heap? plz reply me thank you XD

                                                                                                                            - nbsaw

                                                                                                                              JournalDev
                                                                                                                              DigitalOcean Employee
                                                                                                                              DigitalOcean Employee badge
                                                                                                                              December 27, 2016

                                                                                                                              Hello, i have statement like as below please suggest hoe it will store in which memory, String s1 = “ABC”; String s2 = “ABC”; String s3 = s1; String s3 = new String(“ABC”); String s4 = s3;

                                                                                                                              - Mayur

                                                                                                                                JournalDev
                                                                                                                                DigitalOcean Employee
                                                                                                                                DigitalOcean Employee badge
                                                                                                                                December 31, 2016

                                                                                                                                Hi Pankaj, String abc = “a” + “b” + “c”; Here how many objects created in string pool memory?

                                                                                                                                - Mithun C T

                                                                                                                                  JournalDev
                                                                                                                                  DigitalOcean Employee
                                                                                                                                  DigitalOcean Employee badge
                                                                                                                                  February 28, 2017

                                                                                                                                  On interview I was asked to explain string pool. Unfortunately I did not know answer. Its reason why I read this post. Tnx!

                                                                                                                                  - Gerrix

                                                                                                                                    JournalDev
                                                                                                                                    DigitalOcean Employee
                                                                                                                                    DigitalOcean Employee badge
                                                                                                                                    March 14, 2017

                                                                                                                                    Very good example, Thanks for sharing.

                                                                                                                                    - Dinesh Krishnan

                                                                                                                                      JournalDev
                                                                                                                                      DigitalOcean Employee
                                                                                                                                      DigitalOcean Employee badge
                                                                                                                                      March 15, 2017

                                                                                                                                      String s1=new String(“abc”); Above line will create only one object in the heap, it won’t create two objects as you mentioned (one in heap and one in pool). To put the object in pool you need to call ‘intern()’ on this object, then it checks the pool for existence of this object in the pool, if not available then it will create one in the pool . Example : String s1=new String('abc").intern(); This will check the SCP for “abc” object, if not present then it will create this object and ‘s1’ reference will change to the SCP object and heap object will be dereferenced. Suppose if we change your code like this : String s1=new String(“abc”); s1.intern(); Then this will just create the “abc” object in SCP, but this object will not referred by the reference variable ‘s1’ (as it’s not assigned to ‘s1’). I hope it’s more clear now. Kindly comment if someone having different understanding on the same so that it will help to get correct information on the same. Kindly update the article w.r.t above details, otherwise it will give wrong impression to the reader.

                                                                                                                                      - Shidram Jyoti

                                                                                                                                        JournalDev
                                                                                                                                        DigitalOcean Employee
                                                                                                                                        DigitalOcean Employee badge
                                                                                                                                        May 30, 2017

                                                                                                                                        String s1= “old value of s1”; s1=“new value of s1”; Sysout(s1); It will give new value. Is it possible to get old value as same reference to two different literals are there.

                                                                                                                                        - Purushottam

                                                                                                                                          JournalDev
                                                                                                                                          DigitalOcean Employee
                                                                                                                                          DigitalOcean Employee badge
                                                                                                                                          July 12, 2017

                                                                                                                                          String s1 = “Hello”.concat(“World”); String s3 = new String(“HelloWorld”); //Line-2 String s2 = s1.intern(); System.out.println(s1 == s2); //false System.out.println(s1 == s3); //false System.out.println(s2 == s3); //false If I removed Line-2 and compare s1==s2, it will return true. Could anyone explain me what exactly happens in string pool after Line-2? Thanks

                                                                                                                                          - salman

                                                                                                                                            JournalDev
                                                                                                                                            DigitalOcean Employee
                                                                                                                                            DigitalOcean Employee badge
                                                                                                                                            September 20, 2017

                                                                                                                                            Hello Pankaj, Could you plea address below doubt? Lets say in my Java app I have one calss - A having method for String as setContent and getContent. Now Once I set the String Content using setter method, later I use that object of class A to get that String and put in List using getter method. where that list element will point ? to String pool or somewhere else?

                                                                                                                                            - Tukaram

                                                                                                                                              JournalDev
                                                                                                                                              DigitalOcean Employee
                                                                                                                                              DigitalOcean Employee badge
                                                                                                                                              January 4, 2018

                                                                                                                                              In above statement, either 1 or 2 string will be created. If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. will be created in pool or heap memory(outside pool)?

                                                                                                                                              - Vettaiyan

                                                                                                                                                JournalDev
                                                                                                                                                DigitalOcean Employee
                                                                                                                                                DigitalOcean Employee badge
                                                                                                                                                January 10, 2018

                                                                                                                                                I thought the String Pool just consisted of the actual string value and then the reference to it, str, would be added tot he heap? The object using the string value should be contained in the Heap with the reference to the object on the stack. So the following: String str = new String(“cat”); Should only create one value in the string pool, not 2. “str” is the object containing the reference to “cat” on the pool and that object is in the heap with the reference to the object contained on the stack. If you said how many objects are on the heap, 2 would make sense, but to say 2 strings are created is misleading. The correct answer should be 2 objects, one on the pool and one on the heap is clearer.

                                                                                                                                                - PatrickInBama

                                                                                                                                                  JournalDev
                                                                                                                                                  DigitalOcean Employee
                                                                                                                                                  DigitalOcean Employee badge
                                                                                                                                                  March 28, 2018

                                                                                                                                                  “In above statement, either 1 or 2 string will be created. If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool.” Don’t you notice anything strange here? I think if there already exist one in the pool, then only one will be created only in the heep. will not it be?

                                                                                                                                                  - Hayk

                                                                                                                                                    JournalDev
                                                                                                                                                    DigitalOcean Employee
                                                                                                                                                    DigitalOcean Employee badge
                                                                                                                                                    May 24, 2018

                                                                                                                                                    String str = new String(“Cat”); It will create one String in Heap this is clear. Why it should check in String pool and if it is not there need to create one more.In this case 2 strings memory is allocated internally in the heap[String pool is also part of Heap]. Please clarify this it is confusing me.Below one atleast explain more. In above statement, either 1 or 2 string will be created. If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. If there is no string literal “Cat” in the pool, then it will be first created in the pool and then in the heap space, so total 2 string objects will be created.

                                                                                                                                                    - Ramesh G

                                                                                                                                                      JournalDev
                                                                                                                                                      DigitalOcean Employee
                                                                                                                                                      DigitalOcean Employee badge
                                                                                                                                                      August 29, 2018

                                                                                                                                                      I appreciate it perfect ever !!!

                                                                                                                                                      - Mahdi

                                                                                                                                                        JournalDev
                                                                                                                                                        DigitalOcean Employee
                                                                                                                                                        DigitalOcean Employee badge
                                                                                                                                                        September 1, 2018

                                                                                                                                                        e.g. “Test” has referenced by many reference variables, so if any one of them change the value others will be automatically gets affected i.e. lets say String A = “Test” String B = “Test” Now String B called, “Test”.toUpperCase() which change the same object into “TEST”, so A will also be “TEST” which is not desirable I found this on one website…please clear my doubt about this point. * I done the code but I get the original value of the A “Test” not a “TEST”. after doing uppercase

                                                                                                                                                        - Dhananjay

                                                                                                                                                          JournalDev
                                                                                                                                                          DigitalOcean Employee
                                                                                                                                                          DigitalOcean Employee badge
                                                                                                                                                          October 11, 2018

                                                                                                                                                          @Shidram Jyoti its correct answer, I think. String class intern method also supports this. As per intern() method, it will check first in string pool if string exists or not that means “new String(“abc”)” will not create string in string pool otherwise why “new String(“abc”).intern();” require to check string in string pool if it would have been created string when new String(“abc”).

                                                                                                                                                          - Asish Bajpai

                                                                                                                                                            JournalDev
                                                                                                                                                            DigitalOcean Employee
                                                                                                                                                            DigitalOcean Employee badge
                                                                                                                                                            January 14, 2019

                                                                                                                                                            Hey, Nice read. I have a question though. So, if I create a string object with new operator, 2 objects are created one in string pool (if already not present in string pool) and other in heap, right? So that implies while creating string object with new, string pool is checked if the literal is already present. But doesn’t intern() does the same thing? i.e check in string pool if literal already exist, if not, create new literal

                                                                                                                                                            - Rhicha

                                                                                                                                                              JournalDev
                                                                                                                                                              DigitalOcean Employee
                                                                                                                                                              DigitalOcean Employee badge
                                                                                                                                                              March 20, 2019

                                                                                                                                                              Hi… i think there is a small mistake in :“If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool” - if you have already literal “Cat” in the String pool then only one element will be creared in heap memory…

                                                                                                                                                              - Neshi

                                                                                                                                                                JournalDev
                                                                                                                                                                DigitalOcean Employee
                                                                                                                                                                DigitalOcean Employee badge
                                                                                                                                                                May 1, 2019

                                                                                                                                                                why string object will also be stored in string pool wen it is created using new keyword…

                                                                                                                                                                - ahana

                                                                                                                                                                  JournalDev
                                                                                                                                                                  DigitalOcean Employee
                                                                                                                                                                  DigitalOcean Employee badge
                                                                                                                                                                  May 14, 2020

                                                                                                                                                                  What Code level difference between String and StringBuffer class cause one to be immutable and other to be mutable.

                                                                                                                                                                  - Bhushan parakh

                                                                                                                                                                    Try DigitalOcean for free

                                                                                                                                                                    Click below to sign up and get $200 of credit to try our products over 60 days!

                                                                                                                                                                    Sign up

                                                                                                                                                                    Join the Tech Talk
                                                                                                                                                                    Success! Thank you! Please check your email for further details.

                                                                                                                                                                    Please complete your information!

                                                                                                                                                                    Become a contributor for community

                                                                                                                                                                    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

                                                                                                                                                                    DigitalOcean Documentation

                                                                                                                                                                    Full documentation for every DigitalOcean product.

                                                                                                                                                                    Resources for startups and SMBs

                                                                                                                                                                    The Wave has everything you need to know about building a business, from raising funding to marketing your product.

                                                                                                                                                                    Get our newsletter

                                                                                                                                                                    Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

                                                                                                                                                                    New accounts only. By submitting your email you agree to our Privacy Policy

                                                                                                                                                                    The developer cloud

                                                                                                                                                                    Scale up as you grow — whether you're running one virtual machine or ten thousand.

                                                                                                                                                                    Get started for free

                                                                                                                                                                    Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

                                                                                                                                                                    *This promotional offer applies to new accounts only.