issue 117apr 27mmxxvi
est. 2017
Sun, 27 Apr 2026
vol. IX · no. 117
PapersAdda
placement intelligence, since 2017
640+ briefs · 24 campuses · by reservation
verified offers · sourced from r/developersIndia
razorpay₹65.00 LPA· iit-d · sde-1google₹54.00 LPA· iiit-h · swe-imicrosoft₹49.50 LPA· iit-b · sdeatlassian₹38.00 LPA· nit-w · sde-1amazon₹44.20 LPA· bits-p · sde-1uber₹42.00 LPA· iit-kgp · sde-1razorpay₹65.00 LPA· iit-d · sde-1google₹54.00 LPA· iiit-h · swe-imicrosoft₹49.50 LPA· iit-b · sdeatlassian₹38.00 LPA· nit-w · sde-1amazon₹44.20 LPA· bits-p · sde-1uber₹42.00 LPA· iit-kgp · sde-1

Java String Interview Questions 2026: 27 Q&A With Code

11 min read
Interview Questions
Updated: 8 Jun 2026
Aditya Sharma
Aditya's Edit

PapersAdda 2026 Placement Cycle

By Aditya Sharma·Founder & Editor, PapersAdda

What changed in 2026 drives

Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.

What I'd actually study for this

  • 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
  • 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
  • 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
  • 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken

Where most candidates trip up

The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.

Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.

Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~15 min

Strings appear in nearly every Java interview because they touch immutability, memory, hashing, and performance all at once. Candidates report that the string pool, == versus equals, and StringBuilder versus StringBuffer are guaranteed questions. This guide covers 27 String questions with full answers, runnable code, and predict-the-output traps. Behaviour reflects the official Oracle java.lang.String documentation; confirm any method-level detail on the official docs.

Pair this with Java Interview Questions 2026 and Java Collections Interview Questions 2026.


Table of Contents

  1. Immutability and the Pool (Q1 to Q9)
  2. Comparison and Methods (Q10 to Q18)
  3. StringBuilder and Performance (Q19 to Q24)
  4. Advanced (Q25 to Q27)
  5. Predict the Output
  6. Quick Revision Table
  7. Frequently Asked Questions

Immutability and the Pool

Q1. Why is String immutable in Java? Medium


Q2. What is the string constant pool? Medium

String a = "hi";   // goes to pool
String b = "hi";   // reuses the same pool reference
System.out.println(a == b);   // true

Q3. What is the difference between String literal and new String()? Medium

String x = new String("hi");
System.out.println(x == "hi");          // false
System.out.println(x.intern() == "hi"); // true

Q4. What does the intern() method do? Hard


Q5. How many objects are created by String s = new String("hi")? Hard


Q6. Is String thread-safe? Medium


Q7. Can you extend the String class? Easy



Q9. What is the size of the string pool and where does it live? Hard


Comparison and Methods

Q10. What is the difference between == and equals for strings? Easy


Q11. What is the difference between equals and equalsIgnoreCase? Easy


Q12. What does compareTo return for strings? Medium


Q13. What is the difference between substring in older and newer Java? Hard


Q14. How do you reverse a string in Java? Easy

String reversed = new StringBuilder("abc").reverse().toString(); // "cba"

Q15. How do you check if two strings are anagrams? Medium

boolean anagram(String a, String b) {
    if (a.length() != b.length()) return false;
    int[] count = new int[256];
    for (char c : a.toCharArray()) count[c]++;
    for (char c : b.toCharArray()) if (--count[c] < 0) return false;
    return true;
}

Q16. What does String.split do with a trailing empty string? Hard


Q17. What is the difference between length() for String and length for arrays? Easy


Q18. How do you convert a String to a char array and back? Easy


StringBuilder and Performance

Q19. What is the difference between String, StringBuilder, and StringBuffer? Medium

TypeMutableThread-safeSpeed
StringNoYes (immutable)n/a
StringBuilderYesNoFast
StringBufferYesYesSlower

Q20. Why is string concatenation in a loop inefficient? Medium

StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) sb.append(i);
String result = sb.toString();

Q21. How does the compiler optimise simple string concatenation? Hard


Q22. Is StringBuilder thread-safe? Easy


Q23. How do you efficiently join a list of strings? Medium

String csv = String.join(",", List.of("a", "b", "c")); // "a,b,c"

Q24. What are text blocks in Java? Medium


Advanced

Q25. How does the JVM handle String concatenation with primitives? Medium


Q26. What is the hashCode formula for String? Hard


Q27. What is the difference between isEmpty and isBlank? Easy


Predict the Output

Snippet 1

String a = "java";
String b = "ja" + "va";        // compile-time constant
String c = new String("java");
System.out.println(a == b);
System.out.println(a == c);

Output:

true
false

Why: "ja" + "va" is folded into the literal "java" at compile time and interned, so a == b is true. new String creates a distinct heap object, so a == c is false.


Snippet 2

String s = "abc";
s.concat("def");
System.out.println(s);

Output:

abc

Why: Strings are immutable, concat returns a new string that is discarded here. s is unchanged. You must assign the result.


Snippet 3

System.out.println("5" + 3 + 2);
System.out.println(5 + 3 + "2");

Output:

532
82

Why: Evaluation is left to right. In line 1, the first operand is a string, so everything concatenates. In line 2, 5 + 3 computes 8 first, then concatenates with "2".


Quick Revision Table

ConceptKey takeaway
ImmutabilityEnables pool, thread safety, safe keys
== vs equalsreference vs content
Literal vs newpooled vs fresh heap object
Loop concatuse StringBuilder, not +
StringBuilder vs Bufferunsynchronised vs synchronised
substring leakfixed since Java 7u6
hashCode31-based polynomial, cached

Frequently Asked Questions

Why is String immutable in Java?

Immutability enables safe string-pool sharing, thread safety without locks, safe use as HashMap keys with a cached hash code, and security for sensitive values like file paths. It is the single most asked String concept.

What is the difference between == and equals for strings?

== compares references, equals compares character content. Because of the string pool, == can be accidentally true for literals but breaks for new String. Always use equals for value comparison.

When should I use StringBuilder over String concatenation?

Use StringBuilder whenever you build a string in a loop. Repeated + creates a new String each iteration giving O(n squared) behaviour, while StringBuilder mutates one buffer in O(n).

How do I reverse a string in an interview?

The one-liner is new StringBuilder(s).reverse().toString(), but be ready to do it manually with a two-pointer swap on a char array, since some interviewers want to see the mechanics rather than the library call.

What is the difference between isEmpty and isBlank?

isEmpty is true only for a zero-length string, while isBlank (Java 11+) is also true for strings that contain only whitespace. Use isBlank to treat " " as effectively empty.



Confirm any method-level behaviour on the official Oracle java.lang.String documentation before your interview. This guide reflects candidate-reported patterns and public preparation resources as of June 2026.

Methodology applied to this articlelast verified 8 Jun 2026
Sources used
Public exam-pattern documents, official recruiter pages, and verified candidate reports on r/developersIndia and LinkedIn.
Verification window
Page last edited 8 Jun 2026 by Aditya Sharma. Numbers and patterns sanity-checked against the most recent 2026 cycle drives we tracked.
What we did NOT do
  • No fabricated salary numbers or success rates. If we quote a range, it's sourced.
  • No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
  • No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Verification policy: /editorial-standards/. Found something incorrect? Submit a correction - we respond within 48 hours.

Explore this topic cluster

More resources in Interview Questions

Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.

Paid contributor programme

Sat this this year? Share your story, earn ₹500.

First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.

Submit your story →

Ready to practice?

Take a free timed mock test

Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.

Start Free Mock Test →

Related Articles

More from PapersAdda

Share this guide: