Results 1 to 3 of 3
  1. #1
    powerpravin is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

    Unhappy Adding integer to arraylist

    I declared an arrayList as:
    ArrayList al=new ArrayList();

    And then while trying to add an integer to it with following code

    al.add(inputArray[smallest][index[smallest]]);

    the compiler is throwing an error::confused:
    ----------------------------------------
    Error: cannot resolve symbol
    symbol : method add (int)
    location: class java.util.ArrayList
    ----------------------------------------

    Here 'inputArray' is a two-dimensional array, 'index' is one-dimensional array and 'smallest' is an integer variable.

    Any help will be greatly appreciated.
    Thanks!!
    Last edited by powerpravin; 03-27-2011 at 12:41 PM. Reason: Missed some information in title

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default

    An ArrayList can only carry Object type objects around. The generics compile time features allows you to specify what the actual (sub) type those objects are alllowed to have. Autoboxing (an unrelated feature) does the rest. If you change your ArrayList (the 'raw' List) to an ArrayList<Integer> you're in business.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    powerpravin is offline Member
    Join Date
    Mar 2011
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Adding elements to an ArrayList
    By ArcherSam in forum Advanced Java
    Replies: 7
    Last Post: 01-28-2011, 03:05 PM
  2. Problem in adding arrayList elements
    By cool in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 12:27 PM
  3. Adding books into arrayList
    By mwenchong in forum New To Java
    Replies: 9
    Last Post: 12-15-2010, 02:10 PM
  4. Replies: 3
    Last Post: 11-05-2010, 10:31 AM
  5. adding date in arraylist
    By katturv in forum New To Java
    Replies: 1
    Last Post: 10-23-2010, 06:23 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
  •