🟡 Control Flow  ·  Lesson 14

Strings in Java

Strings in Java

A String is a sequence of characters. In Java, String is a class (not a primitive) and is immutable.

Common Methods

String s = "CodingEasily";
System.out.println(s.length());        // 11
System.out.println(s.toUpperCase());    // CODINGEASILY
System.out.println(s.charAt(0));        // C
System.out.println(s.substring(0, 4));  // Code
System.out.println(s.contains("Funda")); // true

Comparing Strings

Use .equals() to compare String content, NOT == (which compares references).
String a = "hi", b = "hi";
System.out.println(a.equals(b));  // true

Summary

  • String is an immutable class of characters.
  • Methods: length, charAt, substring, toUpperCase, contains.
  • Compare content with .equals(), not ==.

Java में Strings

String characters का sequence है। Java में String एक class है (primitive नहीं) और immutable है।

Common Methods

String s = "CodingEasily";
System.out.println(s.length());        // 11
System.out.println(s.toUpperCase());    // CODINGEASILY
System.out.println(s.charAt(0));        // C
System.out.println(s.substring(0, 4));  // Code
System.out.println(s.contains("Funda")); // true

Strings की तुलना

String content compare करने के लिए .equals() use करें, == नहीं (जो references compare करता है)।
String a = "hi", b = "hi";
System.out.println(a.equals(b));  // true

सारांश

  • String characters की immutable class है।
  • Methods: length, charAt, substring, toUpperCase, contains।
  • Content .equals() से compare करें, == से नहीं।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.