yshak yshak - 4 months ago 5x
Java Question

Trim a string based on the string length

I want to trim a string if the length exceeds 10 characters.

Suppose if the string length is 12 (

String s="abcdafghijkl"
), then the new trimmed string will contain

How can I achieve this?

s = s.substring(0, Math.min(s.length(), 10));