课程: Java Algorithms

今天就学习课程吧!

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

Basic parsing and searching strings in Java

Basic parsing and searching strings in Java - Java教程

课程: Java Algorithms

Basic parsing and searching strings in Java

- [Instructor] A common programming task is to search for a piece of data within a string. Depending on the assumptions you make about a string's data, you can make an algorithm more or less efficient. If you know nothing about the string, you have to check every piece of data within the string in order to find the data you're searching for. If you know the string has its characters in a sorted alphabetical order, then you can optimize the algorithm by starting your search in the front, back, or middle of the string. In all of these cases, you need to parse the data within the string in order to find the character or substring you're looking for. Let's take a look at how to do that in Java. The least complex and least efficient way to search for a subset of characters within a string is to use the built-in contains method. We can use the contains method by accessing the string, in this case s, and we can say s.contains LL. We'll print this out to the console. The contains method will…

内容