Jump to content
xisto Community
Sign in to follow this  
leiaah

Working With Objects In Java searching with objects

Recommended Posts

our teacher assigned us to do an IS that uses object oriented programming language. i decided to use java but im having a few troubles linking objects with other objects when im searching... can anyone help me? tnx.

Share this post


Link to post
Share on other sites

our teacher assigned us to do an IS that uses object oriented programming language.  i decided to use java but im having a few troubles linking objects with other objects when im searching... can anyone help me? tnx.

42557[/snapback]

If you could post the problem here that would be great. Like: What you want, what isn't working, relevant code (if any). :P

Share this post


Link to post
Share on other sites

well i know how to write a file and to read a file but im having trouble searching for one particular object. I put an object ID on each object that I made and I was wondering how to search for it. Should I be using array? thanks.

Share this post


Link to post
Share on other sites

I hope I've understood it right that you have a number of Objects, and each Object has its own ID. And you have to make something that gets an Object when you search for its ID.

In that case I recommend HashTable.

Something like:

Hashtable objects = new Hashtable();hashtable.put("Object#1", new MyObject());

And this to get an object
MyObject o = (MyObject)objects.get("Object#1");


You can think of a HasTable as a table with two columns. One column hold the identifiers/keys the other the Objects.

So if you have an Object you call "ob" and "ob" has a public method called "getID()" which returns the ID, and a HashTable you call "ht" then you can store the Object in the HashTable by:
ht.put(ob.getID(), ob);

Read more here: http://forums.xisto.com/no_longer_exists/

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.