Skip to content
Advertisement

Tag: string

How to determine if a String has non-alphanumeric characters?

I need a method that can tell me if a String has non alphanumeric characters. For example if the String is “abcdef?” or “abcdefà”, the method must return true. Answer Using Apache Commons Lang: Alternativly iterate over String’s characters and check with: You’ve still one problem left: Your example string “abcdefà” is alphanumeric, since à is a letter. But I

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 followed by end of string, you can do:

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 what is

Advertisement