Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Opinion needed - Array List or Linked List

Guessing from your requirements,it would be better to implement your code through a LinkedList.

http://chaoticjava.com/posts/linkedlist-vs-arraylist/
Well,to take in lots of input,create a class CD like this as suggested by SoFlawLess_:

Code
public class CD{
  public String <info_field_0>;
  public String <info_field_1>;
  public String <info_field_2>;
  public CD(String i0,String i1,String i2){
  <info_field_0>=i0;
  <info_field_1>=i1;
  <info_field_2>=i2;
  }
}

Then create an ArrayList or LinkedList in your main class by the name say,cdList by writing it like:

Code
ArrayList<CD> cdList=new ArrayList<CD>();

Then,the function to add to the list will be something like:
Code
public static insertToList(String artist,String name,String date){
  CD cdNew=new CD(artist,name,date);
  cdList.add(cdNew);
}
(Jun 30, 2012 11:02 AM)node.js Wrote:  See that's the problem. Do something like this:

Code
import java.util.ArrayList;

public class CDManager {

    public static void main(String[] args) {
        ArrayList<CD> cds = new ArrayList<CD>();

        CD cd1 = new CD();
        cd1.artist = "SoFlawLess_";
        cd1.name = "Best Hits of SoFlawLess_";
        cds.add(cd1);

        CD cd2 = new CD();
        cd2.artist = "starvinmarvin1";
        cd2.name = "Awesome Hits of starvinmarvin1";
        cds.add(cd2);

        for (CD cd : cds) {
            System.out.println("CD Name: " + cd.name);
            System.out.println("CD Artist: " + cd.artist);
            System.out.println();
        }
    }
}

Code
public class CD {

    public String artist;
    public String name;

}
Reveal the behavior through an interface (for example, List<?>) rather than implementation (ArrayList<?>)

Also, I believe an array list is the better choice.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by gurlhackerclubMay 19, 2020 05:18 PM 8 260 May 19, 2020 05:18 PM
Last Post: k1r3n
[Java] by Juice.Mar 10, 2020 07:02 PM 0 136 Mar 10, 2020 07:02 PM
Last Post: Juice.
[C] by g4143Dec 28, 2019 09:24 AM 1 351 Dec 28, 2019 09:24 AM
Last Post: an balker