Results 1 to 3 of 3
Thread: Adding integer to arraylist
- 03-27-2011, 12:39 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
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
- 03-27-2011, 12:59 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 04-03-2011, 07:21 AM #3
Member
- Join Date
- Mar 2011
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
Adding elements to an ArrayList
By ArcherSam in forum Advanced JavaReplies: 7Last Post: 01-28-2011, 03:05 PM -
Problem in adding arrayList elements
By cool in forum New To JavaReplies: 3Last Post: 01-03-2011, 12:27 PM -
Adding books into arrayList
By mwenchong in forum New To JavaReplies: 9Last Post: 12-15-2010, 02:10 PM -
question about adding using ArrayList using terminal
By chmo in forum New To JavaReplies: 3Last Post: 11-05-2010, 10:31 AM -
adding date in arraylist
By katturv in forum New To JavaReplies: 1Last Post: 10-23-2010, 06:23 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks