Results 1 to 10 of 10
  1. #1
    yma16 is offline Member
    Join Date
    Apr 2011
    Posts
    52
    Rep Power
    0

    Default what does <E> in List<E> mean?

    In Java libaray, there is Interface List<E>.
    what does <E> in List<E> mean?

    Thanks.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    It tells you the type of object that is stored in the List. For example:
    Java Code:
    List<String> myList = new ArrayList<String>();
    Will allow you to only store String objects in the list:
    Java Code:
    list.add( "Hello" ); // this is valid
    list.add( new Integer(1) ); // this is invalid
    Read up on Lesson: Generics (The Java™ Tutorials > Bonus) for more information.

  3. #3
    yma16 is offline Member
    Join Date
    Apr 2011
    Posts
    52
    Rep Power
    0

    Default

    Thank you for your quick replay. Do you know
    1 what ? in addAll(Collection<? extends E> c) mean?
    2 what extends in addAll(Collection<? extends E> c) mean?
    (extends seems to mean any data type that is subclass of E)

  4. #4
    yma16 is offline Member
    Join Date
    Apr 2011
    Posts
    52
    Rep Power
    0

    Default

    Thank you for your quick reply ( not replay).

  5. #5
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default

    ? is the wildcard character, and you are correct that ? extends E means any subclass of E, or E itself.

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by yma16 View Post
    In Java libaray, there is Interface List<E>.
    what does <E> in List<E> mean?

    Thanks.

    <E> is a placeholder and stands for Element and respresents any type of object. for example you can use your own class for E or other java classes like String or Integer. a <K> stands for Key and <V> for Value. for further details read the tuturials related to generics.
    Last edited by j2me64; 04-10-2011 at 08:38 PM.

  7. #7
    yma16 is offline Member
    Join Date
    Apr 2011
    Posts
    52
    Rep Power
    0

    Default ? and extends

    1 What is the purpose of the '?' wildcard character. Could you show me what character can be used and the meaning when it replaces of '?'?

    2 If E means any data type (excludes the primitives), is 'extends' redundant in addAll(Collection<? extends E> c)? It seems '? extends' must be used together.

  8. #8
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    "y extends" is only when you want to specify any class that extends E. It is possible, though, to specify "?" by itself to mean any and all classes.

  9. #9
    yma16 is offline Member
    Join Date
    Apr 2011
    Posts
    52
    Rep Power
    0

    Default Thank you all

    ra4king must be an expert in Java.

  10. #10
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. Replies: 8
    Last Post: 11-04-2011, 08:30 PM
  2. Replies: 2
    Last Post: 11-22-2009, 05:24 PM
  3. Replies: 3
    Last Post: 11-21-2009, 05:48 PM
  4. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  5. How to access ArrayList in List of List?
    By alvations in forum New To Java
    Replies: 5
    Last Post: 10-08-2008, 12:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •