Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Control Flow — Loops, Conditionals & Switch

What is the difference between an array's length and a String's length in Java?

Level I · BeginnerControl Flow — Loops, Conditionals & Switch
Short answer

An array exposes its size as a public final field, `arr.length` (no parentheses), fixed at creation time.

Explanation

A String exposes its size as a method, `s.length()` (with parentheses). Mixing them up -- writing arr.length() or s.length -- is a common beginner compile error. Also note arrays are fixed-size: you cannot grow arr.length; you allocate a new, larger array (or use ArrayList) instead.

Common mistakes
  • Calling array.length() with parentheses or string.length without them.
  • Confusing length (array field), length() (String) and size() (collections).

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Control Flow — Loops, Conditionals & Switch.

Practise free

More on Control Flow — Loops, Conditionals & Switch