What are some of the different ways a developer can create his own List objects?
views:
182answers:
4Crete some object and add property of type array in it. Then you need to implement methods for accessing list items.
I usually get a piece of paper and write things down. I use a dot or dash in front. Like this:
- milk
- eggs
- ice cream
- butter
- oranges
- cereal
and that takes care of the shopping list.
If I make a list for the weekend it is the same piece of paper and looks like:
- mow lawn
- wash car
- walk dog
- clean basement
- fix leak in car tire
I generally cross things off as they are done. Sometimes I reorder the items and prioritize. Usually I end up with lots of half-finished lists and then it all becomes a mess. I sometimes just copy them over to a new/clean sheet and throw the old one in the trash.
There's already a really good explanation of how to implement a linked list in Java on this SO thread.
Many other implementations will be similar, but some, like ArrayList, use an array internally to hold references to list elements. You'll very likely want to implement the List interface, or extend a class like AbstractList that already implements List.