This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 38066
    
  22
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: 3606
    
  60

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: 3606
    
  60

Try this one. It is the Sun's (now Oracle's) own tutorial.
 
 
subject: What are Wildcards?
 
Similar Threads
wild card
Strange prob with Library
Generics and collection
less time...what all to study and revise at last moment for exam?
K & B Mock exam Generics doubt