From the course: Java 8+ Essential Training: Syntax and Structure

Unlock the full course today

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

Parse String values

Parse String values - Java Tutorial

From the course: Java 8+ Essential Training: Syntax and Structure

Start my 1-month free trial

Parse String values

- [Instructor] Java String class includes many methods that you can use to parse information and find sub strings. Also, the wrapper classes for the primitive values have methods that you can use to parse strings and convert them to numeric and other primitive types. For this exercise I'm working in jshell> and I'll start by declaring a string that I'll name s1, and I'll give it a value of "Welcome to California". Next, I'll evaluate the length of that string. I'll create an integer variable that I'll call 'len', and I'll get that value from s1.length. Length is a method of this string class, so you need the opening and closing parentheses at the end. And I get back a value of 22. There are 22 characters in that string. Now, let's say I wanted to find a particular sub string within the string. I want to get the position where the string begins. I'll create another variable that I'll name 'pos' for position. And I'll get it's value from s1.indexOf, and I'll pass in California. And I…

Contents