Java Strings: Concatenation, Memory Allocation, and Comparison Methods

Day 12 of My Java Learning Journey at Tech Academy 🚀 Today’s session was a continuation of Strings in Java, and we explored some very important concepts that strengthened my understanding of how Strings work internally. Here are the key takeaways from today’s lecture 👇 🔹 String Concatenation Concatenation is used to combine two strings. There are two ways to perform concatenation: Using the + operator Using the concat() method 🔹 String Memory Allocation String literals are stored in the String Constant Pool. When we create a string using the new keyword, memory is allocated in the Heap area. Since String is an object, it follows object memory allocation concepts. 🔹 String Comparison Methods equals() → Compares content and returns true or false equalsIgnoreCase() → Compares content ignoring case differences These methods do NOT tell which string is greater or smaller. To compare lexicographically, we use: compareTo() → Returns 0 if equal Positive value if first string is greater Negative value if first string is smaller We tested this method using three different cases to understand it clearly. 🔹 Important Concept In Java, length is a method for Strings (length()), not a property. To extract a character from a String, we use the charAt() method — we cannot access it like an array. Every day, I’m gaining deeper clarity on Java fundamentals and improving my problem-solving skills step by step 💻✨ Excited to continue learning! #Java #JavaProgramming #JavaDeveloper #learningJourney #TechAcademy #Programming #CodingLife #SoftwareDevelopment #WomenInTech #LinkedInLearning #DeveloperJourney #ComputerScience #100DaysOfCode #TechCareer #JavaStrings

  • text, application, chat or text message

To view or add a comment, sign in

Explore content categories