0% found this document useful (0 votes)
12 views4 pages

Java String Character Compact Handbook

This handbook provides essential concepts related to Java Strings, Characters, and StringBuilder, crucial for exams and coding interviews. It covers string immutability, core string methods, character class methods, and the mutable alternative of StringBuilder, along with common interview problems and mistakes. Key methods highlighted include length(), charAt(), substring(), equals(), and others important for interview preparation.

Uploaded by

Tamojoy Chanda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Java String Character Compact Handbook

This handbook provides essential concepts related to Java Strings, Characters, and StringBuilder, crucial for exams and coding interviews. It covers string immutability, core string methods, character class methods, and the mutable alternative of StringBuilder, along with common interview problems and mistakes. Key methods highlighted include length(), charAt(), substring(), equals(), and others important for interview preparation.

Uploaded by

Tamojoy Chanda
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java String & Character – Compact Interview

Handbook

This compact handbook contains all essential String, Character, and StringBuilder concepts
required for exams and coding interviews.

1. String Basics & Immutability


String s1 = "Java";
String s2 = new String("Java");

[Link](s1 == s2); // false


[Link]([Link](s2)); // true

Key Point: Strings are immutable.


2. Core String Methods
String s = "Programming";

[Link](); // 11
[Link](3); // 'g'
[Link](0,6); // Progra
[Link]("ram"); // 4
[Link]("gram"); // true
[Link]();
[Link]();
[Link]();
[Link]("Pro","Go");
[Link]("g");

Comparison Methods:
String a = "apple";
String b = "banana";

[Link](b);
[Link]("APPLE");
3. Character Class Methods
char ch = 'A';

[Link](ch);
[Link](ch);
[Link](ch);
[Link](ch);
[Link]('a');
[Link]('9');

4. StringBuilder (Mutable Alternative)


StringBuilder sb = new StringBuilder("Hello");

[Link](" World");
[Link]();
[Link](0,2);
[Link](sb);
5. Common Interview Problems
// Reverse String
String s = "Java";
String rev = new StringBuilder(s).reverse().toString();

// Palindrome Check
String str = "madam";
boolean isPal = [Link](
new StringBuilder(str).reverse().toString());

// Count Digits
int count = 0;
for(char c : [Link]()){
if([Link](c)) count++;
}

Common Mistakes:
• Using == instead of equals() • Forgetting immutability • Not checking null • Misunderstanding
substring end index (exclusive)

Most Important for Interviews:


length(), charAt(), substring(), equals(), indexOf(), split(), replace(), contains(), [Link](),
[Link]()

You might also like