• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

regex import

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right..!
But regex is a part if util.
So, when we import regex, util will also come.
No?
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right..!! Thanks Henry & Antonio.
I am clear on it now.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic