 1992-2007 Pearson Education, Inc. All rights reserved. 1 30 Strings, Characters and Regular Expressions.

Slides:



Advertisements
Similar presentations
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Strings in Java 1. strings in java are handled by two classes String &
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Java Programming Strings Chapter 7.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 9 Strings and Text I/O.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
Fundamental Programming Structures in Java: Strings.
28-Jun-15 String and StringBuilder Part I: String.
 2006 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
String Escape Sequences
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Characters, String and Regular expressions. Characters char data type is used to represent a single character. Characters are stored in a computer memory.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Characters In Java, single characters are represented.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 7 Strings.
Lecture 14 March 23, Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 9 Strings and Text.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 8 Strings 1.
Regular Expressions.
Portions adapted with permission from the textbook author. CS-1020 Dr. Mark L. Hornick 1 Regular Expressions and String processing Animated Version.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Chapter 7: Characters, Strings, and the StringBuilder.
CHAPTER 9 Text Processing and More about Wrapper Classes Copyright © 2016 Pearson Education, Inc., Hoboken NJ.
1 Textual Data Many computer applications manipulate textual data word processors web browsers online dictionaries.
String Handling StringBuffer class character class StringTokenizer class.
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
Strings Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin, and.
String String Builder. System.String string is the alias for System.String A string is an object of class string in the System namespace representing.
G51PR1 Introduction to Programming I University of Nottingham Unit 8 : Strings.
1 Java Strings Dr. Randy M. Kaplan. 2 Strings – 1 Characters are a fundamental data type in Java It is common to assemble characters into units called.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Java String 1. String String is basically an object that represents sequence of char values. An array of characters works same as java string. For example:
17-Feb-16 String and StringBuilder Part I: String.
Strings, Characters, and Regular Expressions Session 10 Mata kuliah: M0874 – Programming II Tahun: 2010.
String and StringBuffer classes
Strings, Characters and Regular Expressions
Strings, Characters and Regular Expressions
Strings, StringBuilder, and Character
University of Central Florida COP 3330 Object Oriented Programming
Strings, Characters and Regular Expressions
String and String Buffers
String String Builder.
Primitive Types Vs. Reference Types, Strings, Enumerations
Modern Programming Tools And Techniques-I Lecture 11: String Handling
Chapter 7: Strings and Characters
Object Oriented Programming
MSIS 655 Advanced Business Applications Programming
Part a: Fundamentals & Class String
Java – String Handling.
Lecture 07 String Jaeki Song.
CS2011 Introduction to Programming I Strings
JavaScript: Objects.
Dr. Sampath Jayarathna Cal Poly Pomona
Visual Programming COMP-315
Chapter 10 Thinking in Objects Part 2
Object-Oriented Java Programming
In Java, strings are objects that belong to class java.lang.String .
Presentation transcript:

 Pearson Education, Inc. All rights reserved Strings, Characters and Regular Expressions

 Pearson Education, Inc. All rights reserved. 2 The chief defect of Henry King Was chewing little bits of string. —Hilaire Belloc Vigorous writing is concise. A sentence should contain no unnecessary words, a paragraph no unnecessary sentences. —William Strunk, Jr. I have made this letter longer than usual, because I lack the time to make it short. —Blaise Pascal

 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn:  To create and manipulate immutable character string objects of class String.  To create and manipulates mutable character string objects of class StringBuilder.  To create and manipulate objects of class Character.  To use a StringTokenizer object to break a String object into tokens.  To use regular expressions to validate String data entered into an application.

 Pearson Education, Inc. All rights reserved Introduction 30.2 Fundamentals of Characters and Strings 30.3 Class String String Constructors String Methods length, charAt and getChars Comparing Strings Locating Characters and Substrings in Strings Extracting Substrings from Strings Concatenating Strings Miscellaneous String Methods String Method valueOf 30.4 Class StringBuilder StringBuilder Constructors StringBuilder Methods length, capacity, setLength and ensureCapacity StringBuilder Methods charAt, setCharAt, getChars and reverse StringBuilder append Methods StringBuilder Insertion and Deletion Methods 30.5 Class Character 30.6 Class StringTokenizer 30.7 Regular Expressions, Class Pattern and Class Matcher 30.8 Wrap-Up

 Pearson Education, Inc. All rights reserved Introduction String and character processing – Class java.lang.String – Class java.lang.StringBuilder – Class java.lang.Character – Class java.util.StringTokenizer Regular expressions – Valid input – Package java.util.regex – Classes Matcher and Pattern

 Pearson Education, Inc. All rights reserved Fundamentals of Characters and Strings Characters – “Building blocks” of Java source programs – Character literals – Unicode character set String – Series of characters treated as single unit – May include letters, digits, special characters. – Object of class String – String literals

 Pearson Education, Inc. All rights reserved. 7 Performance Tip Java treats all string literals with the same contents as a single String object that has many references to it. This conserves memory.

 Pearson Education, Inc. All rights reserved Class String Class String – Represent strings in Java

 Pearson Education, Inc. All rights reserved String Constructors Fig demonstrates four constructors – No-argument constructor – One-argument constructor A String object – One-argument constructor A char array – Three-argument constructor A char array An integer specifies the starting position An integer specifies the number of characters to access

 Pearson Education, Inc. All rights reserved. 10 Software Engineering Obervation 30.1 It is not necessary to copy an existing String object. String objects are immutable—their character contents cannot be changed after they are created, because class String does not provide any methods that allow the contents of a String object to be modified.

 Pearson Education, Inc. All rights reserved. 11 Outline StringConstructors.java Line 12 Line 13 Line 14 Line 15 Program output No-argument constructor creates an empty string One-argument constructor creates a String that contains the same sequence of characters as the String argument One-argument constructor creates a String that contains a copy of the characters in the array argument Three-argument constructor creates a String that contains a copy of partial characters in the array argument

 Pearson Education, Inc. All rights reserved. 12 Common Programming Error 30.1 Attempting to access a character that is outside the bounds of a string (i.e., an index less than 0 or an index greater than or equal to the string’s length) results in a StringIndexOutOfBoundsException.

 Pearson Education, Inc. All rights reserved String Methods length, charAt and getChars Method length – Determine the length of a String Like arrays, String s always “know” their size Unlike array, String s do not have length instance variable Method charAt – Get character at specific location in String Method getChars – Get entire set of characters in String

 Pearson Education, Inc. All rights reserved. 14 Outline StringMiscellaneou s.java (1 of 2) Line 15 Lines Determine number of characters in String s1 Display the characters of the string s1 in reverse order

 Pearson Education, Inc. All rights reserved. 15 Outline StringMiscellaneou s.java (2 of 2) Line 24 Program output Copy (some of) s1 ’s characters to charArray

 Pearson Education, Inc. All rights reserved Comparing Strings Comparing String objects – Method equals – Method equalsIgnoreCase – Method compareTo – Method regionMatches

 Pearson Education, Inc. All rights reserved. 17 Outline StringCompare.java (1 of 3) Line 17 Line 23 Method equals tests two objects for equality using lexicographical comparison Equality operator ( == ) tests if both references refer to same object in memory

 Pearson Education, Inc. All rights reserved. 18 Outline StringCompare.java (2 of 3) Line 29 Lines Line 47 Test two objects for equality, but ignore case of letters in String s Method compareTo compares String objects Method regionMatches compares portions of two String objects for equality

 Pearson Education, Inc. All rights reserved. 19 Outline StringCompare.java (3 of 3) Program output

 Pearson Education, Inc. All rights reserved. 20 Common Programming Error 30.2 Comparing references with == can lead to logic errors, because == compares the references to determine whether they refer to the same object, not whether two objects have the same contents. When two identical (but separate) objects are compared with ==, the result will be false. When comparing objects to determine whether they have the same contents, use method equals.

 Pearson Education, Inc. All rights reserved. 21 Outline StringStartEnd.java (1 of 2) Lines 13 and 22 Method startsWith determines if String starts with specified characters

 Pearson Education, Inc. All rights reserved. 22 Outline StringStartEnd.java (2 of 2) Line 32 Program output Method endsWith determines if String ends with specified characters

 Pearson Education, Inc. All rights reserved Locating Characters and Substrings in Strings Search for characters in String – Method indexOf – Method lastIndexOf

 Pearson Education, Inc. All rights reserved. 24 Outline StringIndexMethods.java (1 of 3) Lines 12, 14 and 16 Lines 20, 22 and 24 Method indexOf finds first occurrence of character in String Method lastIndexOf finds last occurrence of character in String

 Pearson Education, Inc. All rights reserved. 25 Outline StringIndexMethods.java (2 of 3) Lines 28, 30, 32, 36, 38 and 40 Methods indexOf and lastIndexOf can also find occurrences of substrings

 Pearson Education, Inc. All rights reserved. 26 Outline StringIndexMethods.java (3 of 3) Program output

 Pearson Education, Inc. All rights reserved Extracting Substrings from Strings Create String s from other String s – Method substring

 Pearson Education, Inc. All rights reserved. 28 Outline SubString.java Line 12 Line 15 Program output Beginning at index 20, extract characters from String letters Extract characters from index 3 to 6 from String letters

 Pearson Education, Inc. All rights reserved Concatenating Strings Method concat – Concatenate two String objects

 Pearson Education, Inc. All rights reserved. 30 Outline StringConcatenatio n.java Line 13 Line 14 Program output Concatenate String s2 to String s1 However, String s1 is not modified by method concat

 Pearson Education, Inc. All rights reserved Miscellaneous String Methods Miscellaneous String methods – Return modified copies of String – Return character array

 Pearson Education, Inc. All rights reserved. 32 Outline StringMiscellaneou s2.java (1 of 2) Line 16 Line 19 Line 20 Line 23 Use method replace to return s1 copy in which every occurrence of ‘ l ’ is replaced with ‘ L ’ Use method toUpperCase to return s1 copy in which every character is uppercase Use method toLowerCase to return s2 copy in which every character is uppercase Use method trim to return s3 copy in which whitespace is eliminated

 Pearson Education, Inc. All rights reserved. 33 Outline StringMiscellaneou s2.java (2 of 2) Line 26 Program output Use method toCharArray to return character array of s1

 Pearson Education, Inc. All rights reserved String Method valueOf String provides static class methods – Method valueOf Returns String representation of object, data, etc.

 Pearson Education, Inc. All rights reserved. 35 Outline StringValueOf.java (1 of 2) Line 12 Line 13 Use literal value L as the initial values of long variable Use literal value 2.5f as the initial values of float variable

 Pearson Education, Inc. All rights reserved. 36 Outline StringValueOf.java (2 of 2) Lines Program output static method valueOf of class String returns String representation of various types

 Pearson Education, Inc. All rights reserved Class StringBuilder Class StringBuilder – When String object is created, its contents cannot change – Used for creating and manipulating dynamic string data i.e., modifiable String s – Can store characters based on capacity Capacity expands dynamically to handle additional characters – Uses operators + and += for String concatenation

 Pearson Education, Inc. All rights reserved. 38 Performance Tip 30.2 Java can perform certain optimizations involving String objects (such as sharing one String object among multiple references) because it knows these objects will not change. String s (not StringBuilder s) should be used if the data will not change.

 Pearson Education, Inc. All rights reserved. 39 Performance Tip 30.3 In programs that frequently perform string concatenation, or other string modifications, it is more efficient to implement the modifications with class StringBuilder (covered in Section 30.4).

 Pearson Education, Inc. All rights reserved StringBuilder Constructors Four StringBuilder constructors – No-argument constructor Creates StringBuilder with no characters Capacity of 16 characters – One-argument constructor int argument – Specifies the initial capacity – One-argument constructor String argument Creates StringBuilder containing the characters in the String argument

 Pearson Education, Inc. All rights reserved. 41 Outline StringBuilderConst ructors.java Line 8 Line 9 Line 10 Lines Program output No-argument constructor creates empty StringBuilder with capacity of 16 characters One-argument constructor creates empty StringBuilder with capacity of specified ( 10 ) characters One-argument constructor creates StringBuilder with String “ hello ” and capacity of 16 characters Method toString returns String representation of StringBuilder

 Pearson Education, Inc. All rights reserved StringBuilder Methods length, capacity, setLength and ensureCapacity Method length – Return StringBuilder length Method capacity – Return StringBuilder capacity Method setLength – Increase or decrease StringBuilder length Method ensureCapacity – Set StringBuilder capacity – Guarantee that StringBuilder has minimum capacity

 Pearson Education, Inc. All rights reserved. 43 Outline StringBuilderCapLe n.java Line 11 Line 13 Line 16 Program output Method length returns StringBuilder length Method capacity returns StringBuilder capacity Use method ensureCapacity to set capacity to 75 Use method setLength to set length to 10 Only 10 characters from StringBuilder are printed

 Pearson Education, Inc. All rights reserved. 44 Performance Tip 30.4 Dynamically increasing the capacity of a StringBuilder can take a relatively long time. Executing a large number of these operations can degrade the performance of an application. If a StringBuilder is going to increase greatly in size, possibly multiple times, setting its capacity high at the beginning will increase performance.

 Pearson Education, Inc. All rights reserved StringBuilder Methods charAt, setCharAt, getChars and reverse Manipulating StringBuilder characters – Method charAt Return StringBuilder character at specified index – Method setCharAt Set StringBuilder character at specified index – Method getChars Return character array from StringBuilder – Method reverse Reverse StringBuilder contents

 Pearson Education, Inc. All rights reserved. 46 Outline StringBuilderChars.java (1 of 2) Line 12 Line 15 Return StringBuilder characters at indices 0 and 4, respectively Return character array from StringBuilder

 Pearson Education, Inc. All rights reserved. 47 Outline StringBuilderChars.java (2 of 2) Lines 21 and 22 Line 25 Program output Replace characters at indices 0 and 6 with ‘ H ’ and ‘ T,’ respectively Reverse characters in StringBuilder

 Pearson Education, Inc. All rights reserved. 48 Common Programming Error 30.3 Attempting to access a character that is outside the bounds of a StringBuilder (i.e., with an index less than 0 or greater than or equal to the StringBuilder ’s length) results in a StringIndexOutOfBoundsException.

 Pearson Education, Inc. All rights reserved StringBuilder append Methods Method append – Allow data values to be added to StringBuilder

 Pearson Education, Inc. All rights reserved. 50 Outline StringBuilderAppen d.java (1 of 3)

 Pearson Education, Inc. All rights reserved. 51 Outline StringBuilderAppen d.java (2 of 3) Line 21 Line 23 Line 25 Line 27 Lines 29, 31, 33, 35, 37 and 39 Line 41 Append String “ hello ” to StringBuilder Append a new line character to StringBuilder Append String “ goodbye ”Append “ a b c d e f ”Append “ a b c ” Append boolean, char, int, long, float and double Append StringBuilder

 Pearson Education, Inc. All rights reserved. 52 Outline StringBuilderAppen d.java (3 of 3) Program output

 Pearson Education, Inc. All rights reserved StringBuilder Insertion and Deletion Methods Method insert – Allow data-type values to be inserted into StringBuilder Methods delete and deleteCharAt – Allow characters to be removed from StringBuilder

 Pearson Education, Inc. All rights reserved. 54 Outline StringBuilderInser t.java (1 of 3)

 Pearson Education, Inc. All rights reserved. 55 Outline StringBuilderInser t.java (2 of 3) Lines Use method insert to insert data in beginning of StringBuilder

 Pearson Education, Inc. All rights reserved. 56 Outline StringBuilderInser t.java (3 of 3) Line 43 Line 44 Program output Use method deleteCharAt to remove character from index 10 in StringBuilder Remove characters from indices 2 through 5 (inclusive)

 Pearson Education, Inc. All rights reserved Class Character Treat primitive variables as objects – Type wrapper classes Boolean Character Double Float Byte Short Integer Long – We examine class Character

 Pearson Education, Inc. All rights reserved. 58 Outline StaticCharMethods. java (1 of 3) Line 12 Obtain first character of the input string

 Pearson Education, Inc. All rights reserved. 59 Outline StaticCharMethods. java (2 of 3) Line 15 Line 16 Line 18 Line 20 Line 21 Line 23 Lines 25 and 27 Lines 29 and 31 Determine whether c is defined Unicode character set Determine whether c can be used as first character in identifier Determine whether c is defined Unicode digit Determine whether c can be used as identifier character Determine whether c is a letter Determine whether c is letter or digit Determine whether c is lowercase and uppercase, respectively Convert c to its uppercase and lowercase, respectively

 Pearson Education, Inc. All rights reserved. 60 Outline StaticCharMethods. java (3 of 3) Program output

 Pearson Education, Inc. All rights reserved. 61 Outline StaticCharMethods2.java (1 of 2) Line 28 Use method forDigit to convert int digit to number-system character specified by int radix

 Pearson Education, Inc. All rights reserved. 62 Outline StaticCharMethods2.java (2 of 2) Line 35 Program output Use method digit to convert char c to number-system integer specified by int radix

 Pearson Education, Inc. All rights reserved. 63 Outline OtherCharMethods.j ava Lines 8-9 Line 12 Line 14 Program output Assign two character literals to two Character objects. Auto-boxing occurs. Obtain the char value stored in Character object c1 Method toString returns a string representation of the Character object Use method equals to determine whether c1 has the same contents as c2

 Pearson Education, Inc. All rights reserved Class StringTokenizer Tokenizer – Partition String into individual substrings – Use delimiter Typically whitespace characters (space, tab, newline, etc) – Java offers java.util.StringTokenizer

 Pearson Education, Inc. All rights reserved. 65 Outline TokenTest.java Line 17 Line 19 Lines Program output Use StringTokenizer to parse String using default delimiter “ \n\t\r ” Count number of tokensDisplay next token as long as tokens exist

 Pearson Education, Inc. All rights reserved Regular Expressions, Class Pattern and Class Matcher Regular expression – Sequence of characters and symbols – Useful for validating input and ensuring data format E.g., ZIP code – Facilitate the construction of a compiler Regular-expression operations in String – Method matches Matches the contents of a String to regular expression Returns a boolean indicating whether the match succeeded

 Pearson Education, Inc. All rights reserved Regular Expressions, Class Pattern and Class Matcher (Cont.) Predefine character classes – Escape sequence that represents a group of character – Digit Numeric character – Word character Any letter, digit, underscore – Whitespace character Space, tab, carriage return, newline, form feed

 Pearson Education, Inc. All rights reserved. 68 Fig | Predefined character classes.

 Pearson Education, Inc. All rights reserved Regular Expressions, Class Pattern and Class Matcher (Cont.) Other patterns – Square brackets ( [] ) Match characters that do not have a predefined character class E.g., [aeiou] matches a single character that is a vowel – Dash ( - ) Ranges of characters E.g., [A-Z] matches a single uppercase letter – ^ Not include the indicated characters E.g., [^Z] matches any character other than Z

 Pearson Education, Inc. All rights reserved Regular Expressions, Class Pattern and Class Matcher (Cont.) Quantifiers – Plus (+) Match one or more occurrences E.g., A+ – Matches AAA but not empty string – Asterisk ( * ) Match zero or more occurrences E.g., A* – Matches both AAA and empty string – Others in Fig

 Pearson Education, Inc. All rights reserved. 71 Fig | Quantifiers used in regular expressions.

 Pearson Education, Inc. All rights reserved. 72 Outline ValidateInput.java (1 of 2) Lines 9, 15, 22 and 28 Method matches returns true if the String matches the regular expression

 Pearson Education, Inc. All rights reserved. 73 Outline ValidateInput.java (2 of 2) Method matches returns true if the String matches the regular expression

 Pearson Education, Inc. All rights reserved. 74 Outline Validate.java (1 of 3)

 Pearson Education, Inc. All rights reserved. 75 Outline Validate.java (2 of 3)

 Pearson Education, Inc. All rights reserved. 76 Outline Validate.java (3 of 3) Program output Indicate that the entry for “zip” was invalid

 Pearson Education, Inc. All rights reserved Regular Expressions, Class Pattern and Class Matcher (Cont.) Replacing substrings and splitting strings – String method replaceAll Replace text in a string with new text – String method replaceFirst Replace the first occurrence of a pattern match – String method split Divides string into several substrings

 Pearson Education, Inc. All rights reserved. 78 Outline RegexSubstitution. java (1 of 2) Line 14 Line 19 Line 26 Replace every instance of “ * ” in firstString with “ ^ ” Replace every instance of “ stars ” in firstString with “ carets ” Replace every word in firstString with “ word ”

 Pearson Education, Inc. All rights reserved. 79 Outline RegexSubstitution. java (2 of 2) Line 32 Line 38 replaceFirst replaces a single occurrence of the regular expression split returns array of substrings between matches of the regular expression

 Pearson Education, Inc. All rights reserved Regular Expressions, Class Pattern and Class Matcher (Cont.) Class Pattern – Represents a regular expression Class Match – Contains a regular-expression pattern and a CharSequence – Interface CharSequence Allows read access to a sequence of characters String and StringBuilder implement CharSequence

 Pearson Education, Inc. All rights reserved. 81 Common Programming Error 30.4 A regular expression can be tested against an object of any class that implements interface CharSequence, but the regular expression must be a String. Attempting to create a regular expression as a StringBuilder is an error.

 Pearson Education, Inc. All rights reserved. 82 Outline RegexMatches.java (1 of 2) Lines Line 20 Line 22 Line 23 Program output compile creates a Pattern object for regular expression matcher creates the Matcher object for the compiled regular expression and the matching sequence find gets the first substring that matches the regular expression group returns the string from the search object that matches the search pattern

 Pearson Education, Inc. All rights reserved. 83 Common Programming Error 30.5 Method matches (from class String, Pattern or Matcher ) will return true only if the entire search object matches the regular expression. Methods find and lookingAt (from class Matcher ) will return true if a portion of the search object matches the regular expression.