We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › object positin within an arraylist
Page Index Toggle Pages: 1
object positin within an arraylist (Read 700 times)
object positin within an arraylist
Feb 9th, 2010, 12:26am
 
Can an object know it's own position within an arraylist?

Say I have a class dot and put many dots in an arraylist, can the dot-class itself somehow use the "index" of the obejct in that arraylist?

I can for sure pass on the index when creating the list, but that value wouldn't shift when any object is inserted or delete before that position.

Is there an easy way out, or do I have to "manage" the object ID's each time I manipulate the list?
Re: object positin within an arraylist
Reply #1 - Feb 9th, 2010, 12:59am
 
Check out the ArrayList documentation.  I suspect what you're after is IndexOf() though it's not clear from your description exactly what you want to do...
Re: object positin within an arraylist
Reply #2 - Feb 9th, 2010, 9:56am
 
Thanks. Problem with the reference is, that I use Processing on an offline-computer. Can I get a good reference for full download somewhere?

Anyway, I am not sure if I found what I need, so I will explain my task a little more with an example (It is abstract and not the actual aim, but it is simpler to illustrate.)

I have an object class called link.
I create an arraylist of these objects, basically creating a chain out of "link" objects. Now within the link-class I want to have a function which acts on the actual position of the object within the arraylist. Say the 2nd "link" in my chain gets a certain color, the 3rd another one etc.

Could I thus write a code which kind "locates" the object "self" in any arraylist? If yes, a simple exmple code would be great.
Re: object positin within an arraylist
Reply #3 - Feb 9th, 2010, 10:08am
 
> Thanks. Problem with the reference is, that I use Processing on an offline-computer.
> Can I get a good reference for full download somewhere?

it's there, as part of the download.

in fact it's integrated into the IDE - just highlight a keyword and use right-click to being up the context menu - 'find in reference'.

the complete reference is available from a Help menu item.
Page Index Toggle Pages: 1