From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Parsing string values

Parsing string values - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Parsing string values

- Java's String class includes many methods that you can use to parse information and find substrings. I'll show you some of them here in the project ParsingStrings. I've declared a string with a value of Welcome to California. And first, I'll display the length of that string. I'll use some System output and I'll start with a label of Length of string and I'll pinch to that the expression s1.length. Length is a method of the String class. I'll run that code and the result is Length of string: 22. Now, let's say that I wanted to find a particular substring within that string. You can do that with a method named indexOf. It returns an integer value, so I'll create a variable named position declared as an int and I'll get its value by calling s1.indexOf. And I'll pass in the substring I'm looking for. Then I'll output that information to the console starting with Position of substring and then outputting the position. And the result is Position of substring: 11. Now, just as with…

Contents