> For the complete documentation index, see [llms.txt](https://gyansetu-java.gitbook.io/core-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-java.gitbook.io/core-java/string/string-constant-pool.md).

# String Constant Pool

**Examine the below code snippet:**

```java
package com.test.test1;
public class StringPool {
	public static void main(String[] args) {
		String str3 = "Harry";
		String str4 = "Harry";
		System.out.println(str3);
		System.out.println(str4);
	}
}
```

**What will happen behind the scenes?**

![](/files/-LTaUDDiRu5EQiHXZ5py)

![](/files/-LTaUI3nci2allAYHkxk)

**Lets validate:**

![](/files/-LTaUopJ5nn1M6xRw3O0)

```java
package com.test.test1;
public class StringPool {
	public static void main(String[] args) {
		String s1 = "Cat";
		String s2 = "Cat";
		String s3 = new String("Cat"); 
		if(s1==s2)
		{
			System.out.println("s1 and s2 are pointing to same string "+s1);
		}
		else
		{
			System.out.println("s1 and s2 are not pointing to same string "+s1);
		}
		if(s1==s3)
		{
			System.out.println("s1 and s3 are pointing to same string "+s1);
		}
		else
		{
			System.out.println("s1 and s3 are not pointing to same string "+s1);
		}
	}
}

```

#### Problem: Count the number of strings.

![](/files/-LTadsPWCaiBPE9jcE5A)
