Skip to content
QuizMaker logoQuizMaker
Activity
Java Backend Interview Prep

No lessons available

CONTENTS

14. Sorting, Maps, Strings, and Character Checks

Practice common interview snippets for sorting, maps, equality, and digit checks.

Java Backend Interview Prep
3. OOP & DSA Revision
May 29, 2026
21
A

Sorting

Use Arrays.sort(array) for arrays and Collections.sort(list) or list.sort(comparator) for lists.

For custom objects, implement Comparator<T> or pass a lambda comparator:

students.sort(Comparator.comparing(Student::getRollNo));

Maps

getOrDefault is common for frequency counting:

count.put(word, count.getOrDefault(word, 0) + 1);

Sort map entries by value by copying entrySet() into a list and sorting with Map.Entry.comparingByValue().

Strings and Characters

Use .equals() for String content comparison. == compares references for objects.

Use Character.isDigit(c) and Character.isLetter(c) for character classification.

Interview Scenario Practice

Scenario 1: Group Anagrams

Scenario: You need to group words that contain the same characters.

Strong answer: Sort each word's characters and use the sorted string as a map key, or use a character-count signature.

Why it works: Anagrams share the same normalized representation.

Common mistake: Comparing every pair of words, which is much slower.

Scenario 2: String Equality Bug

Scenario: new String("A") == "A" returns false.

Strong answer: Use .equals() for String content comparison. == compares object references.

Why it works: Two different String objects can contain the same characters.

Common mistake: Relying on string pool behavior instead of using equals().

Scenario 3: Validate Character Input

Scenario: A program asks for one character and needs to check whether it is a digit.

Strong answer: Read the string, take charAt(0) carefully, and use Character.isDigit(c).

Why it works: The Character utility class handles character classification clearly.

Common mistake: Comparing character ranges manually without considering readability or Unicode behavior.

Share this article

Test your knowledge

Take a quick quiz based on this chapter.

mediumJava Backend Interview Prep
Quiz: Sorting and String Checks
8 questions8 min

0 comments

Please login to comment.
No comments yet.
Lesson 4 of 5 in 3. OOP & DSA Revision
Previous in 3. OOP & DSA Revision
13. Collections Comparison Cheat Sheet
Next in 3. OOP & DSA Revision
15. Binary Trees, BSTs, Stacks, and Queues
Back to Java Backend Interview Prep
Back to moduleCategories