# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gyansetu-java.gitbook.io/core-java/string/string-constant-pool.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
