This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes What are Wildcards? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "What are Wildcards?" Watch "What are Wildcards?" New topic
Author

What are Wildcards?

Umesh Kilkile
Greenhorn

Joined: Mar 31, 2010
Posts: 11
Hi,

Explain me simple words or
Please suggest me any good site,where I can learn Wildcards.

Thank You,

Umesh K
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

a wildcard represents something unknown or undefined.
As a basic example we use '?' to represent a single character and '*' to represents zero or more characters
So test?.txt matches test1.txt testA.txt but not test.txt or testAB.txt
test*.txt matches everything test?.txt matches and a bunch more.

Learn by doing. Regular Expressions are all about matching patterns and make extensive use of wildcards.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43935
    
  33
Whihch wildcards? You get wildcards (as David O'M has already told you) in regular expressions, and also in actual type parameters for generics. Probably elsewhere too.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

but in a general sense both represent "something unknown or undefined"
eg List<T> is a "List of something"
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3718
    
  61

eg List<T> is a "List of something"

Just to clarify, I don't think this is an example of wildcard. T in this case is a type parameter. Wildcard would be the question mark in List<?>.
Umesh Kilkile
Greenhorn

Joined: Mar 31, 2010
Posts: 11
Hi,

Actually I wanted to learn using wildcards in Java and in Generics.

Please help me.

Thank You,

Umesh
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3718
    
  61

Try this one. It is the Sun's (now Oracle's) own tutorial.
 
Have you checked out Aspose?
 
subject: What are Wildcards?
 
It's not a secret anymore!