how to set the length of a string in java code example Example: length of string in java str.length();