I am initalizing several objects of the same type that have a common field:
public class Example { private static objectCounter = 1; public Example () { objectCounter++; } } Since these objects are created with a for loop like this
for (int i = 0; i<5; i++) { Example e = new Example(); } they are not referenced.
Is there a way to get a specific object based on objectCounter value ?
Something like
//get the Example object with objectCounter==2 get(2); Thank you
Exampleobjects will have the same value forobjectCounter(referenced byExample.objectCounter). You need to assign your counter to a non static variable if you want to distinguish your objects by that value.