Skip to content

Tag: substring

Capitalization of the words in string

How can I avoid of StringIndexOutOfBoundsException in case when string starts with space (” “) or when there’re several spaces in the string? Actually I need to capitalize first letters of the words in the string. My code looks like: Tests: Input: “test test test” Output: “…

Find substring in List and return Index Number

I have an List, with Strings like: Now i would like to get the Index Number for the Substring “One”. How can i get this? I only could make it if i convert it to an Array and then: Isn’t there a way to search for the Substring without converting it to an Array? Answer List already contains in…

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…