Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can i make a container class to hold my objects?

801510Dec 21 2008 — edited Dec 21 2008
question, is there a way to find out if a specific element exists in an object array?
I have this

public class ServerManager
{
Server servers[];


private static List<Servers>allServers,availableServers,busyServers;

public ServerManager() throws Exception
{
Load.loadFile(); //loads the servers in class Load
layoutConfig=LayoutConfig.getInstance();
allServers=new ArrayList<Server>();
availableServers=new ArrayList<Server>();
busyServers=new ArrayList<Server>();
initServers(Load.servers);

}
public void initServers(Server [] Server)
{
for(int i=0; i<totalServers; i++)
{
allServers.add(Server);
availableServers.add(Server[i]);
//Server.clean(Server[i]);
}
Object[] objArray = allServers.toArray();
for (int j=0; j < objArray.length; j++)
{
System.out.println("Array Element [" + j + "] = " + objArray[j]);

}

}
public void releaseServer(Server Server)
{
availableServers.remove(Server);
busyServers.add(Server);
}
public static Server[] getServers()
{


int n=Servers.size();

Server results[] = new Server[n];
Enumeration containers = Servers.elements();
for (int i = 0; i < n; i++)
results[i] = (Server) containers.nextElement();
System.out.println(results);
System.out.println(Servers.toString());
return (results);

}
}

someone told me i should have a class that is a container for all the servers, but how would i access a container class from ServerManager if want to say getServers()? would a hashtable or arraylist be better to be a container for server objects?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2009
Added on Dec 21 2008
4 comments
44 views