Results 1 to 4 of 4
  1. #1
    katiebear128 is offline Member
    Join Date
    Sep 2011
    Posts
    54
    Rep Power
    0

    Default ArrayLists- generic?

    Write a statement that creates an ArrayList of strings called myList and then puts the String "Apple" on the list. Note: you must create a generic ArrayList.


    my answer:
    Java Code:
     ArrayList myList=new ArrayList();
    myList.add("Apple");
    the error that comes up says I must create a generic ArrayList...but I thought I did that?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: ArrayLists- generic?

    Your ArrayList is not generic as it doesn't use the angle brackets <...>. Please read the tutorial on generics. Google can show you hundreds of these.

  3. #3
    katiebear128 is offline Member
    Join Date
    Sep 2011
    Posts
    54
    Rep Power
    0

    Default Re: ArrayLists- generic?

    thanks for reminding me...added <String> & it worked.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. how to concatenate two arraylists in a third one
    By nanees in forum New To Java
    Replies: 14
    Last Post: 03-31-2011, 06:08 PM
  2. Problem with ArrayLists
    By fatedorigin in forum New To Java
    Replies: 1
    Last Post: 03-15-2011, 01:18 AM
  3. ArrayLists
    By Freakzoyd in forum New To Java
    Replies: 4
    Last Post: 11-12-2010, 05:27 AM
  4. [SOLVED] A better way to do this - ArrayLists
    By Tshegofatsom in forum New To Java
    Replies: 13
    Last Post: 05-20-2009, 03:05 PM

Tags for this Thread

Posting Permissions

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