+ 2
How to find the number of objects inside (a) methode/s in a java program?
4 Réponses
- 1
public class Main {
public static void main(String[] args) {
int[] numbers={'1','2','3'};
System.out.println(numbers.length); // 3
}
}
+ 4
Hmm.... Sounds to me like you want to create a big code smell. What exactly are you trying to do? Do you need a list of your objects? Then put them in a collection, e.g. a List<MyObjects> -> some list containing your objects.
+ 2
actually it's a simple question.... I just need to find how many objects do I have in my simple code.....
+ 1
You can use a counter...
static int counter= 0;
and then in the constructors:
counter++;