I wonder why java defines homogeneous methods in two distinct classes: java.util.regex.Pattern and java.util.regex.Matcher.

For example split method defined in Pattern class and replaceAll method defined in Matcher class. I think these two methods are homogeneous, why are they not defined in the same class?

Have I understood it wrong?

By "homogenous", I mean: split and replaceAll methods are utilities for String, why not defined in a class?

  • What do you mean when you say "homogenous"? I don't understand the question. Mar 5, 2012 at 8:51
  • My means is: split and replaceAll methods are utilities for string, why not defined in a class?
    – Sam
    Mar 5, 2012 at 8:55
  • 1
    I'm guessing it is for historic reasons, but maybe someone knows the specifics. Mar 5, 2012 at 15:02
  • @GarrettHall maybe this opinion is correct.
    – Sam
    Mar 5, 2012 at 15:37

2 Answers 2


I'm guessing there's a or more historical reasons because you say correct, those classes have homogenous methods.


Not certain to be right, but :

When you create a regex, you have to cut/look inside the object you are searching for.
You have to know how it is made : you make a tool (split()) to detect the Pattern you like.

But when you use this tool, you want to make it usefull, so each time your pattern matches, you apply the rule pre-defined (replaceAll()).
How can you apply it if you do not know on what, this is not the same gesture/movement, so not the same class?

Forget you are a programmer and enrole you like an artisan, if now it is not obvious, find another point of view.
It is an language problem, each person have its meaning of words, often it is the same between them, sometime not, you have to guess what is behind the words wrotten which perturb your analysis.

Good 'declic'

Best regards Claude

  • Sorry about the lateness :I've not seen the tool 'inbox', I discorver it today. I tried to say : you see those classes homogeneous, detect their different behaviours, so you can apply a method to one, and the other to the second. One is the touchstone/give the law, the second the tool to compare/react face to a situation --> in OO things different have classes different -?- Not certain to be more understandable.
    – cl-r
    Mar 26, 2012 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.