Java String Basics: Immutable vs Mutable Strings

🔹 Today I learned about Strings in Java • A String is a sequence of characters enclosed in double quotes. • In Java, Strings are objects used to store and manipulate text. 🔹 Types of Strings • Immutable Strings – Once created, their value cannot be changed Examples: name, date of birth, gender • Mutable Strings – Their value can be changed Examples: password, email, months of the year 🔹 Ways to Create Strings • Using new keyword → String s1 = new String("java"); • Without new keyword → String s2 = "java"; 🔹 Memory Allocation (Heap Segment) • String Constant Pool (SCP) – Does not allow duplicate values – Strings created without new are stored here • Heap Area – Allows duplicate objects – Strings created with new are stored in the heap 🔹 Ways to Compare Strings • == → Compares references (memory locations) • equals() → Compares values • compareTo() → Compares strings character by character • equalsIgnoreCase() → Compares values ignoring case differences #TapAcademy #Java #JavaProgramming #LearningJava #StringConcept #ProgrammingBasics #CodingJourney #TechLearning

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories