Java Strings Interview Questions

Strings appear in almost every Java interview, both as theory and as live coding. This topic covers what interviewers ask beyond the basics: how many objects new String creates, intern(), why + is slow inside loops, null-safe conversion with String.valueOf, isEmpty versus isBlank, the traps of split(), why String makes a good HashMap key and why passwords belong in a char[].

It also explains how switch on Strings works internally, Compact Strings in Java 9 and the old substring memory leak, and finishes with popular coding problems: anagrams, reversing the words of a sentence, string rotation and the longest common prefix. Every answer includes a complete program with its real output and a ready-to-use interview answer.