Java Strings
Work with text, one operation at a time.
முக்கிய விளக்கங்கள் தமிழில் உள்ளன. Runnable example மற்றும் கூடுதல் practice notes ஆங்கிலத்தில் உள்ளன.
இந்தப் பாடத்தில்…
- Explain the key idea behind Strings.
- Read and run a complete example, then predict what changes.
- Recognize the topic-specific mistake discussed below.
அடிப்படையைப் புரிந்துகொள்ளுங்கள்
A String holds text. String objects are immutable: operations such as toUpperCase return another String rather than changing the original object. Use equals for content comparisons, and check the bounds before requesting a substring.
விரிவான விளக்கங்கள்
Java Strings என்னன்னு தெரியுமா?
Strings என்பது characters-ஓட sequence — text-ஐ store பண்ணவும் manipulate பண்ணவும் use ஆகுது.
Java-ல String double quotes-க்கு உள்ளே இருக்கும்:
String Length
String-ஓட length தெரிஞ்சுக்க length() method பயன்படுத்தலாம்:
Useful String Methods
toUpperCase()— எல்லா letters-உம் uppercase ஆகும்toLowerCase()— எல்லா letters-உம் lowercase ஆகும்indexOf()— குறிப்பிட்ட character-ஓட position கொடுக்கும்concat()— இரண்டு strings-ஐ join பண்றதுக்குtrim()— ஆரம்பம் மற்றும் முடிவுல இருக்குற spaces remove ஆகும்replace()— ஒரு value-ஐ இன்னொரு value-ஆ மாத்துது
String Concatenation
Strings-ஐ + operator use பண்ணி join பண்ணலாம்:
String-ஐ number-உடன் add பண்ணா, result string ஆகும் — numeric addition நடக்காது.
String s = "Hello, Java!";
System.out.println(s.length()); // 12
System.out.println(s.toUpperCase()); // HELLO, JAVA!
System.out.println(s.substring(7, 11)); // Java
System.out.println(s.contains("Java")); // true
System.out.println(s.replace("Java", "World")); // Hello, World!
System.out.println(s.charAt(0)); // H
// Comparing — always use .equals()
String a = "hello", b = "hello";
System.out.println(a.equals(b)); // true ✓
System.out.println(a.equalsIgnoreCase("HELLO")); // trueLoop-க்கு உள்ளே String Concatenation avoid செய்யவும்: str = str + value என்று loop-ல் use செய்தால் ஒவ்வொரு iteration-லும் புதிய String object create ஆகும் — memory waste! இதற்கு பதில் StringBuilder பயன்படுத்தவும்: StringBuilder sb = new StringBuilder(); பிறகு sb.append(value); — இது production code-ல் ஒரு standard practice.
முழுமையான உதாரணம்
This complete Main.java program focuses on the lesson idea. Reference fragments above may demonstrate individual statements; this example includes the imports, entry point, and supporting types it needs.
public class Main {
public static void main(String[] args) throws Exception {
String topic = "Java";
System.out.println(topic.toUpperCase());
System.out.println(topic);
System.out.println(topic.equals("Java"));
System.out.println(topic.length());
}
}Predict first. Then reveal the expected output / வெளியீடு
JAVA Java true 4
The output shown was checked by running this complete example. Trace the executed statements in order, then compare with your run.
Change it. Run it. Understand it.
Load this lesson example into the editor. Change one value or statement, predict the result, then press RUN to execute Java.
Powered by OneCompiler. Code you run is sent to OneCompiler for execution. For Scanner examples, supply input in the editor I/O panel; for file examples, files exist in its execution environment.
நீங்களே முயற்சி செய்யுங்கள்
Practice challenge
Store the result of toUpperCase back into topic and print it again.
Reveal the answer and reasoning / விடை
Use topic = topic.toUpperCase();. Subsequent reads of topic now refer to the uppercase String.
தவிர்க்க வேண்டிய தவறு: == checks object-reference identity for Strings. It is not the usual way to compare their text.
பாடத்தின் சுருக்கம்
- Explain the example without reading the output first.
- Make the change requested in the practice task.
- Describe why the result changed—or why compilation failed.
Ready to move on? Follow the next lesson in course order, or return to the curriculum to review a prerequisite.