Results 1 to 2 of 2
  1. #1
    josefK is offline Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    0

    Default Problems with an ArrayList declaration.

    Hello everyone, i have a problem with an ArrayList.
    First of all, can an arrayList contain primitive kind of data such as int or char?
    And why it gives this error " '(' or '[' expected " to the following line of code?


    Java Code:
    private ArrayList<int> numeriEstratti=new ArrayList<int>;

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

    Default Re: Problems with an ArrayList declaration.

    generic types can only be objects not primitives -- so change <int> to <Integer>. You'll also want to include ArrayList's parenthesis when you call its constructor:

    Java Code:
    private ArrayList<Integer> foo = new ArrayList<Integer>(); // don't forget the parenthesis!

Similar Threads

  1. Having problems clearing an arrayList
    By zenitis in forum New To Java
    Replies: 8
    Last Post: 05-05-2011, 10:29 PM
  2. How to implement boolen in this arraylist problems?
    By Vin5253 in forum New To Java
    Replies: 1
    Last Post: 02-07-2011, 05:31 AM
  3. Problems with a loop calling data from an ArrayList.
    By moriarty in forum New To Java
    Replies: 30
    Last Post: 03-28-2010, 04:00 AM
  4. ArrayList problems
    By komo225 in forum New To Java
    Replies: 4
    Last Post: 02-12-2009, 05:14 AM
  5. [Problems] ArrayList
    By Zuela in forum New To Java
    Replies: 1
    Last Post: 06-16-2008, 12:51 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
  •