Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does <E> mean in the 1.5.0 API docs? 1

Status
Not open for further replies.

markbanker

Programmer
Mar 6, 2001
37
US
I have noticed in the 1.5.0 API docs that <E> is used a great deal. Can someone tell me what it means?

Examples:
Interface Collection<E>
public interface Set<E> extends Collection<E>
add(E o)

Often times the 'E' is hyperlinked but when I click it it takes me to the Collections Interface.

I am unable to find any explanation for its usage.

Any feedback will be greatly appreciated.

Thanks,
Mark
 
In Java 1.5, you can now specify what kind of Objects you want your Collections to hold. The <E> denotes this object type. It's best illustrated with an example:

Java 1.4.2:
Code:
ArrayList list = new ArrayList();
list.add( "add a string" );
String str = (String) list.get( 0 );
Notice that, since your ArrayList can only hold Objects, you have to cast the variable you retrieve from it as a String (in this case). With Java 1.5, we'll now specify that the contents of `list' are all Strings:
Code:
ArrayList<String> list = new ArrayList<String>();
list.add( "add a string" );
String str = list.get( 0 );

You can read more on Generics (as this is called) here
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top