1 What is the difference between String objects and StringBu
1. What is the difference between \'String\' objects and \'StringBuilder\' objects?
2, List and define three methods contained in class \'Matcher\'
Solution
1 Ans) The main difference between \'String\' objects and \'StringBuilder\' objects is that \'String\' objects are immutable whereas \'StringBuilder\' objects are mutable. By immutable it means that the value of a String object cannot be changed. So, whenever we perform some operations on String object which changes the value of String internally a new String object will be created. But \'StringBuilder\' objects are mutable means that their value can be changed and no new StringBuilder objects will be created when we change the value.
2 Ans) The \'Matcher\' class is used to search a string for multiple occurrences of a regular expression.
Below are the examples of three methods contained in \'Matcher\' class
1)public boolean matches()
The matches() method returns true if regular expression is matched against the whole string passed to the Pattern.matcher() method when the Matcher was created , otherwise returns false
2)public boolean lookingAt()
The lookingAt() method returns true if regular expression is matched against the starting of the string passed to the Pattern.matcher() method when the Matcher was created , otherwise returns false
3)public boolean find()
The find() method searches for occurrences of the regular expressions in the text passed to the Pattern.matcher(text) method, when the Matcher was created. If multiple matches are found in the text, the find() method will find the first, and then for each subsequent call to find() it will move to the next match.
