Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Working With Objects In Java, searching with objects
leiaah
post Jan 23 2005, 07:38 AM
Post #1


Super Member
*********

Group: Members
Posts: 436
Joined: 21-January 05
From: Koronadal City, Philippines
Member No.: 3,358



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.
Go to the top of the page
 
+Quote Post
bjrn
post Jan 23 2005, 11:59 AM
Post #2


Super Member
*********

Group: Members
Posts: 378
Joined: 8-January 05
Member No.: 3,174



QUOTE(leiaah @ Jan 23 2005, 09:38 AM)
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.
*


If you could post the problem here that would be great. Like: What you want, what isn't working, relevant code (if any). smile.gif
Go to the top of the page
 
+Quote Post
leiaah
post Feb 6 2005, 06:48 AM
Post #3


Super Member
*********

Group: Members
Posts: 436
Joined: 21-January 05
From: Koronadal City, Philippines
Member No.: 3,358



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.
Go to the top of the page
 
+Quote Post
bjrn
post Feb 6 2005, 01:22 PM
Post #4


Super Member
*********

Group: Members
Posts: 378
Joined: 8-January 05
Member No.: 3,174



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:
CODE

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


And this to get an object
CODE

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://java.sun.com/j2se/1.4.2/docs/api/ja.../Hashtable.html
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Ajax - A New Technology(10)
  2. Flash - Streaming Flv With Interactible Objects(3)


 



- Lo-Fi Version Time is now: 7th October 2008 - 04:43 AM