---
title: "Discussion on \"Why Strings are immutable in Java?\" | Hashnode"
description: "Discussion on \"Why Strings are immutable in Java?\". The String is immutable in Java because of its security, thread safety, and memory utilization. Let's go through each reason one by one.\n1. Memory space utilization \nWhen we declare a string variable,\n\nin memory it looks like this, \n\nThe name variabl..."
url: "https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why Strings are immutable in Java?](https://shashankbhatgs.hashnode.dev/why-strings-are-immutable-in-java?utm_source=hashnode&utm_medium=feed)

The String is immutable in Java because of its security, thread safety, and memory utilization. Let's go through each reason one by one. 1. Memory space utilization When we declare a string variable, in memory it looks like this, The name variabl...

Jun 19, 2022 · 2 min read · shashankbhatgs.hashnode.dev  
Read the article

-   [#java](https://hashnode.com/tag/java)

## Written by

[Shashank Bhat G S](https://hashnode.com/@shashankbhatgs)

@shashankbhatgs · India

  
[View profile](https://hashnode.com/@shashankbhatgs)

Undergraduate

Hi everyone👋 I am Shashank, and currently in my sophomore year, doing my undergraduate in India. I'm currently learning web development and DSA and share my journey here. Also, an open-source enthusiast and interested in DevOps and Blockchain I love to interact with the community and help each other out.

## Responses 3

Markdown supported · ⌘↵ to post

[Shai Almog](https://hashnode.com/@talktotheduck)

[Jun 19, 2022](https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e/comment/62aeea490924134a804892ef)

Great post!

Also I think the reason is to make it a bit more consistent with the behavior of the primitive types.

I would also add that the JVM can then do some [pretty cool optimizations](https://www.baeldung.com/java-9-compact-string) to Strings seamlessly thanks to that...

[Shashank Bhat G S](https://hashnode.com/@shashankbhatgs)

[Jun 22, 2022](https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e/comment/62aeea490924134a804892ef#reply-62b353c386d22092a7546d0d)

Thanks for the point

[Harshit](https://hashnode.com/@avionicharshit)

[Jun 19, 2022](https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e/comment/62aee2cad8afe74aa51fc695)

I finally understood the concept of immutability of string objects in java, thank you for that.

[Shashank Bhat G S](https://hashnode.com/@shashankbhatgs)

[Jun 19, 2022](https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e/comment/62aee2cad8afe74aa51fc695#reply-62aee51dd8afe74aa51fc6cb)

You're welcome :)

[yaodao](https://hashnode.com/@yaodao)

[Jun 19, 2022](https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e/comment/62aed50ed8afe74aa51fc4c2)

Good artical!

[Shashank Bhat G S](https://hashnode.com/@shashankbhatgs)

[Jun 19, 2022](https://hashnode.com/posts/why-strings-are-immutable-in-java/62aec7a30924134a80488f8e/comment/62aed50ed8afe74aa51fc4c2#reply-62aee498d8afe74aa51fc6ba)

Thank you!
