> 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?**

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTaTQbwi80UdZQmEiKL%2F-LTaUDDiRu5EQiHXZ5py%2Fimage.png?alt=media\&token=638e74bb-62c2-43da-bf2a-928bfdb299de)

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTaTQbwi80UdZQmEiKL%2F-LTaUI3nci2allAYHkxk%2Fimage.png?alt=media\&token=a662d6df-8a0a-487a-9a5f-190ad1e0a69c)

**Lets validate:**

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTaTQbwi80UdZQmEiKL%2F-LTaUopJ5nn1M6xRw3O0%2FString-Pool-Java1.png?alt=media\&token=c618f92d-b792-42a1-8b16-bc26a9eebf09)

```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.

![](https://3494582050-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LSemf7mp1liQa7nfIAC%2F-LTadLZfI4ONbnlTLV-R%2F-LTadsPWCaiBPE9jcE5A%2Fimage.png?alt=media\&token=dbcedbac-7b89-457d-95d0-dc8becc63242)
