Java Programming Lesson 7 Part-1 | String class & methods for Beginners
LESSON-7 STRINGS IN JAVA
Strings (String class & methods)
✅ What is String?
A String is a sequence of characters stored as an object in Java.
Example:
Property ✅
✔ String is immutable (cannot be changed once created)
✅ String Declaration Methods
✅ String Input from User
✅ Most Important String Methods
| Method | Meaning | Example Output |
|---|---|---|
length() | Count characters | "Java".length() → 4 |
toUpperCase() | Convert to capital | "java".toUpperCase() |
toLowerCase() | Convert to small | "HELLO".toLowerCase() |
charAt(i) | Get character | "Java".charAt(1) → 'a' |
equals() | Compare strings | "A".equals("a") → false |
contains() | Substring present? | "coding".contains("cod") |
replace() | Replace characters | "java".replace('a','o') |
substring() | Cut part | "Hello".substring(1,4) |
✅ Practical Example
✅ Output:
✅ Compare Strings: equals() vs ==
📌 Use equals() to compare text values ✔
📝 Exercise for You ✅
Create a String program:
Input from user:
✅ Full Name
Program should:
✔ Print total characters
✔ Print uppercase version
✔ Print first character
✔ Check whether name contains "a" or "A"
Example Output:
Reply with your:
✅ Code
✅ Output
I’ll check & give grading ✅🔥
🎯 Quick Quiz
1️⃣ String is:
A) Primitive
B) Non-Primitive
2️⃣ Which method compares text values?
A) ==
B) equals()
C) compare()
Reply like:
1 → ?, 2 → ?
✅ Lesson-7 Part-1 Completed!

No comments
Thank You For Visit My Website.
I Will Contact As Soon As Possible.