![]() |
|
[Java] Opinion needed - Array List or Linked List - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Opinion needed - Array List or Linked List (/showthread.php?tid=2634967) |
Opinion needed - Array List or Linked List - starvinmarvin1 - Jun 30, 2012 So basically I need to make a program which stores cd information and I need to write it to file.I need to be able to: Add, Edit or Delete the information So I used the Array List but when written to file the contents are a little shoddy. I need your opinion will it be better to stay with the array list or maybe go with the linked list? * - anuvab1911 - Jun 30, 2012 Guessing from your requirements,it would be better to implement your code through a LinkedList. http://chaoticjava.com/posts/linkedlist-vs-arraylist/ * - starvinmarvin1 - Jun 30, 2012 (Jun 30, 2012 10:32 AM)anuvab1911 Wrote: Guessing from your requirements,it would be better to implement your code through a LinkedList. Thanks for your input🤝. . .I was hoping to stay with the array list but I guess I should just stop being lazy * - node.js - Jun 30, 2012 Wait, How are you storing the cd information? Is this a String ArrayList? * - starvinmarvin1 - Jun 30, 2012 (Jun 30, 2012 10:53 AM)SoFlawLess_ Wrote: Wait, How are you storing the cd information? Is this a String ArrayList? Sorry I mention this, yes it is a String Array list * - node.js - Jun 30, 2012 (Jun 30, 2012 10:54 AM)starvinmarvin1 Wrote: Sorry I mention this, yes it is a String Array list See that's the problem. Do something like this: Code import java.util.ArrayList;Code public class CD {* - starvinmarvin1 - Jun 30, 2012 (Jun 30, 2012 11:02 AM)SoFlawLess_ Wrote: See that's the problem. Do something like this: You make Java seem easy bro. . .but how am I going to take lots of input ? Thanks for your help🤝 * - anuvab1911 - Jun 30, 2012 Well,to take in lots of input,create a class CD like this as suggested by SoFlawLess_: Code public class CD{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){* - starvinmarvin1 - Jul 1, 2012 Thanks for your help guys. Got it sorted * - Jire - Jul 1, 2012 (Jun 30, 2012 11:02 AM)SoFlawLess_ Wrote: See that's the problem. Do something like this:Reveal the behavior through an interface (for example, List<?>) rather than implementation (ArrayList<?>) Also, I believe an array list is the better choice. |