From the course: Learning Java 11
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Using indexes with strings - Java Tutorial
From the course: Learning Java 11
Using indexes with strings
- [Narrator] Now that we have the student's first and last name separated we can calculate the student's first initial from the first name and last initial from the last name. All we need to do is somehow grab the first letter of the first name and the first letter of the last name to create each initial. Earlier we talked about how the ordering of the letters within a string matters. And this is one place where that comes into play. For the string Kayla, we say K is at index or location zero. A is at index one, Y is at index two, L is at index three and A is at index four. This means to calculate the first initial of the first name we'll want to access the character at index zero, or the zeroth slot in the string. To do this we can use a special string operator to access the letters inside first name. To grab the first character of the first name we can use an operation called charAt. CharAt allows us to access a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.