Results 1 to 4 of 4
  1. #1
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Question ArrayList or class ?

    Hi,

    I have a class with options for a device.
    This class contains the name and some info.

    I want to include these opions in a device.

    Is it beter to include an ArrayList<Option> in the device class or to create a class that contains this arrayList and to include this class into the device class

    Java Code:
    private ArrayList<Option> options;
    or
    Java Code:
    private Options options;
    Kind regards
    Dipke

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: ArrayList or class ?

    It depends on your use-case. If you plan on having operations that manipulate the collect (like sorting, or custom things) and you want this functionality to follow the collection around (like a data structure, think trees or maps or the like), then make a class. If the only thing you ever do is just hold the collection, and maybe send it somewhere (like for printing, or saving or whatever), then just keeping an ArrayList<type> is fine.

    So, it really depends on your requirements. Adding abstraction for the sake of abstraction is bad. Abstract things if and only if it makes more sense and improves the readability, maintainability, or functionality of the system.

  3. #3
    Dipke is offline Member
    Join Date
    Aug 2010
    Location
    Leuven, Belgium
    Posts
    86
    Rep Power
    0

    Default Re: ArrayList or class ?

    Hi,

    In fact there are some manupilations like adding with equal check but there is no need for using this elsewhere.
    So i will use an ArrayList.

    Thanks for the answer

    Kind regards
    Dipke

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

Similar Threads

  1. Access ArrayList from another class!!!
    By hassaanid2012 in forum New To Java
    Replies: 7
    Last Post: 04-15-2012, 04:00 PM
  2. Getting a second, third, fourth arraylist from a class
    By Paul_White in forum New To Java
    Replies: 3
    Last Post: 12-02-2011, 05:10 AM
  3. Get an ArrayList from another class
    By ScienceLife in forum New To Java
    Replies: 5
    Last Post: 04-09-2011, 11:13 AM
  4. Java Arraylist (.get from other class)
    By Kingarmy in forum New To Java
    Replies: 1
    Last Post: 12-28-2010, 09:00 PM
  5. Help passing arraylist to another class
    By adlb1300 in forum New To Java
    Replies: 3
    Last Post: 11-06-2007, 09:02 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
  •