string length validation in java code example Example 1: length of string in java str.length(); Example 2: java length of string string.length()