Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I need help on ArrayList  RSS feed

 
Eric Teo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

When we create a new thread, we will normally have some variables right? For example, we might have the address so we need a getAddress method to retrieve the address.

I create an array using ArrayList(). Can anyone teach me how to retrieve the whole list?

Thanks in advance!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,

Welcome to JavaRanch!

Are these two separate questions? Your two paragraphs don't sound related to each other. Can you perhaps ask your question(s) again, in a bit more detail this time?
 
Eric Teo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

public CreateNode(String name, int aIPAddress, int aBandWidth)
{
super(name);
List myFiles = new ArrayList();
}

public List getFileList()
{
return myFiles;
}

The CreateNode is actually the constructor for my thread. I need to be able to return myFiles. Can you help?
Thanks!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, your getFileList() method seems to do that just fine.

CreateNode node = new CreateNode("nodename", 76265276257, 1200);
List myList = node.getFileList();

What else do you need to do?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch again Eric.

What is your goal? Do you need by a chance an instance of a resource associated with each thread. The class ThreadLocal
holds a table mapping a Thread to a variable. The variable is set by aThreadLocal.set(Object) the thread is the one calling that method. In order to retrieve it use aThreadLocal.get() that yields the variable corresponding to the calling thread. Though the API recommeds the initialValue method to set the variable only once.

If this is not what you want, declare myFiles out of the constructor.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!