课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Normalize strings in Java

Normalize strings in Java - Java教程

课程: Java Algorithms

Normalize strings in Java

- [Instructor] Before processing a string, it can be helpful to normalize it to a common form in order to make your algorithm more efficient. Let's say you're searching for a particular letter within a string. You could search for that letter once in the lowercase form, and once in the uppercase form, this means you would have to run two different searches to find out if the letter exists. Another way to go about this is to convert the string to all lower case. With this approach, you could search for the letter in the lowercase form and only have to search for one form of the letter. With two forms, you're still iterating through the string twice, but if the number of forms the letter can appear increases, the amount you have to search stays the same. It also makes your code less complex by searching for one form of the data. This is one way to normalize your string data, converting all the characters to a certain case, uppercase or lowercase. Instead of normalizing your input…

内容