Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-22-2007, 01:12 AM
dabbler dabbler is offline
Newbie
 
Join Date: Aug 2007
Posts: 1
Rep Power: 0
dabbler is on a distinguished road
Default LinkedList of Objects?

Hi I had a quick question. Can the LinkedList in util be used to form a List of any objects, including instances of classes I create? How would I do that?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 08-22-2007, 10:09 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,470
Last Blog:
Joomla! And Incompeten...
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

I believe any lists can be used to hold any data type, ATD's or objects. I don't have eclipse on my computer at the moment, but to use it, it should be the same as adding any item to the list.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-11-2007, 08:22 PM
mungojelly mungojelly is offline
Newbie
 
Join Date: Sep 2007
Posts: 1
Rep Power: 0
mungojelly is on a distinguished road
Default LinkedList !

Hello, I'm new to Java as well, so I'm happy to be able to answer your question.

You can make a LinkedList to hold any kind of object, including classes you've made yourself. If you've made a class named Foo, then you can make a new LinkedList of Foo objects like this:

Code:
LinkedList<Foo> listOfFoos = new LinkedList<Foo>();
The first part, "LinkedList<Foo> listOfFoos", is a declaration of the name listOfFoos, declaring that it's of the type "a LinkedList set up to hold objects of type Foo." The second part, "new LinkedList<Foo>()", makes an actual object which is "a LinkedList set up to hold objects of type Foo." The object is plucked from the ether (that is, constructed) and a reference to it is associated with the name "listOfFoos". Now you can use that name to do anything that a LinkedList does:

Code:
listOfFoos.add(new Foo());
listOfFoos.removeLast();
if (listOfFoos.size() < 12) { ... }
I believe if you just say LinkedList without the < > you'll get a generic version that can hold anything. Another way to ask for a linked list that can hold anything is to say LinkedList<Object> -- that can hold anything which is an Object or a subclass of Object, aka everything.

HTH.

<3
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
G++ Error: cannot pass objects of non-POD type Ronin C and C++ 4 10-01-2007 05:35 AM
[Query]TreeMap and TreeSet objects. How to use? Musashibo Java Help 0 06-05-2007 10:18 AM
Java:Tutorial - Adding more objects to your window John Java Tutorials 0 01-11-2007 03:09 PM
Classes, Methods, and Objects Sionofdarkness Java Help 6 08-21-2006 01:55 PM
Objects Nightracer General Programming 8 07-28-2006 09:02 PM


All times are GMT -5. The time now is 11:59 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads