From the course: Nail Your Java Interview

Unlock the full course today

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

Normalize string input

Normalize string input - Java Tutorial

From the course: Nail Your Java Interview

Start my 1-month free trial

Normalize string input

- [Narrator] When developing a solution to a technical interview question, you'll often need to normalize the user's input or the data you're working with. This could mean taking out white space, making sure all the characters are lowercase or alphabetical, or more. As a part of the string data type we get a few methods for free. But you have to know what they are in order to use them in an interview. Let's take a look. In this code we have a few string variables. We've put these in a list, so they're easier to work with. Just looking at these strings, the first thing I really want to do is trim off the white space at the front and the back. Using the list, we can create a stream to access each string individually and print out the trimmed response. We'll write animals.stream.fourEach to access each individual string. We'll run a .trim on it and we'll print out that result to the console, taking away those…

Contents