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

    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


    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.
    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
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    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,

    Build a wall around Donald Trump; I'll pay for it.

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

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