KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is the difference between the pattern() method and the toString() method in the Pattern class? The doc says: public String pattern() Returns the regular expression from which this pattern was compiled. public String toString() Returns the string representation of this pattern. This is the regular expression from which this pattern was compiled. Even their implementation returns the same result: import java.util.regex.*; class Test { public static void main(String[] args) { Pattern p = Pattern.compile("[a-zA-Z]+\\.?"); String s = p.pattern(); String d = p.toString(); System.out.println(s); System.out.println(d); } } I see no difference, so why are there two methods? Or am I missing something?
Tags (comma-separated)
Save Edits
Cancel