• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regex import

 
Lovleen Gupta
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In import statements - if I write import java.util.*, it doesn't let me use Pattern, Matcher classes in the program.
However, if I use import java.util.regex.*, it let me do it..

Now, the question is -- Is java.util.regex.* not a subset of java.util.* ?
So, if I am using only util.* , it should let me use the regex classes also..

Please explain.

Thanks.
 
Antonio Trapero
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With import sentence, you will bring only one package at time or one class, not subpackages.

import java.util.*; only brings this package, no subpackages like regex.
import java.util.regex.*; only brings package regex.
import java.util.regex.Pattern; only brings Pattern class.
 
Lovleen Gupta
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right..!
But regex is a part if util.
So, when we import regex, util will also come.
No?
 
Henry Wong
author
Marshal
Pie
Posts: 20828
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lovleen Gupta:
Right..!
But regex is a part if util.
So, when we import regex, util will also come.
No?


As Antonio mentioned. No, the import statement only specify classes. Hence...

import java.util.*;

means import all the *classes* in the java.util package. Although regex is in the util directory (as an implementation detail), it is not a class, hence, not imported.

Henry
 
Lovleen Gupta
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All right..!! Thanks Henry & Antonio.
I am clear on it now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic