From the course: Java Cheat Codes: Most Popular Functions

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: toCharArray()

Solution: toCharArray()

(upbeat music) - [Instructor] So as I mentioned in the challenge, the to char array method is amazing for deciphering hidden messages within strings or altering strings. So to solve this challenge, I'm actually going to start in the tester class and then explain the answer class, and there are a ton of different ways that we could solve this, so this is just one of many, and I've also added in some bonus ways to utilize the to char array method. So to start off, we create an answer object with our sample string, so as I mentioned, we're going to use "Hello, world." You can add an exclamation point, make sure you have a space in between, and the first way we're going to utilize the to char array method is that we're going to convert the character array and print out individual characters, so you'll see that we will print out each of the characters within "Hello, world!" separately, and another method of using the to char array is that we will then go in and modify a specific character…

Contents