Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-2007, 11:27 AM
Senior Member
 
Join Date: Nov 2007
Posts: 115
ravian is on a distinguished road
Getting objects of a class
I have a class named Facility. I created 3 objects of it. During program execution, more objects will be created. Now I want some way to get all the objects of the class named Facility. Some iterator or something would do.

Code:
Facility obj1 = new Facility (); Facility obj2 = new Facility ("Facility NY",10); Facility obj3 = new Facility ();
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-04-2007, 01:23 PM
Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 90
wsaryada is on a distinguished road
I think you should store your object is some sort of array or collections and get it later by iterating the array of collections. You can then check whether your class is an instance of Facility class using the instanceof construct.

Code:
for (int i = 0; i < collection.size(); i++) { Object obj = collection.get(i); if (obj instanceof Facility) { // do something with the object } }
__________________
Website:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by wsaryada : 12-04-2007 at 01:26 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Color objects CyberFrog New To Java 4 04-01-2008 01:41 AM
Getting objects from a list markyoung1984 New To Java 4 03-13-2008 11:45 PM
Objects and Classes Aleve New To Java 8 12-31-2007 09:05 AM
how can objects themselves be copied??? ishakteyran New To Java 1 12-29-2007 11:04 AM
Help with Objects! Shorinhio New To Java 1 07-10-2007 10:32 PM


All times are GMT +3. The time now is 04:18 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org