Skip to content
Advertisement

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: “Test Test Test” Input: ” test test test” Output: Expected: ” Test Test test”

Finding second occurrence of a substring in a string in Java

We are given a string, say, “itiswhatitis” and a substring, say, “is”. I need to find the index of ‘i’ when the string “is” occurs a second time in the original string. String.indexOf(“is”) will return 2 in this case. I want the output to be 10 in this case. Answer Use overloaded version of indexOf(), which takes the starting index

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 indexes

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