Understanding Java Strings: Creation, Comparison, and Concatenation

Day 21: Strings in Java Today’s learning was all about understanding how Strings work internally in Java from creation to comparison and concatenation. 🔹 What is a String? A String is a sequence of characters enclosed in double quotes (" " ), whereas a character uses single quotes (' ' ). ➡️ Multiple characters cannot be stored in single quotes. 🔹 Types of Strings Strings are classified into two types: Mutable Strings – values can be changed Immutable Strings – values cannot be changed (default in Java) 🔹 Ways to Create a String in Java Using new keyword Using string literals Using character arrays 🔹 String Comparison Methods Java provides multiple ways to compare strings: == → compares reference (memory address) equals() → compares values/content equalsIgnoreCase() → compares values ignoring case compareTo() → compares character by character (lexicographically) 🔹 Where Are Strings Stored in Memory? Strings are stored in the Heap Segment of the JRE Heap is divided into: Constant Pool – no duplicates allowed Non-Constant Pool – duplicates allowed 🔹 String Pool Concept Strings created without new keyword → Constant Pool Strings created using new keyword → Non-Constant Pool 🔹 String Concatenation String concatenation means combining multiple strings to form a new string. Can be done using: + operator concat() method 📌 Understanding Strings is crucial for memory management and performance in Java. #Day21 #Java #StringsInJava #CoreJava #Programming #LearningJourney #TapAcademy #JavaDeveloper

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories