Skip to content

Tag: string

Remove trailing comma from comma-separated string

I got String from the database which have multiple commas (,) . I want to remove the last comma but I can’t really find a simple way of doing it. What I have: kushalhs, mayurvm, narendrabz, What I want: kushalhs, mayurvm, narendrabz Answer To remove the “, ” part which is immediately followe…

Trim String in Java while preserve full word

I need to trim a String in java so that: The quick brown fox jumps over the laz dog. becomes The quick brown… In the example above, I’m trimming to 12 characters. If I just use substring I would get: The quick br… I already have a method for doing this using substring, but I wanted to know w…