+ 2

How to find the number of objects inside (a) methode/s in a java program?

28th Aug 2017, 5:00 PM
Mohamed Sajjadh
Mohamed Sajjadh - avatar
4 ответов
- 1
public class Main { public static void main(String[] args) { int[] numbers={'1','2','3'}; System.out.println(numbers.length); // 3 } }
1st Sep 2017, 11:16 PM
Ahmos Ahmed
Ahmos Ahmed - avatar
+ 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.
28th Aug 2017, 5:53 PM
Tashi N
Tashi N - avatar
+ 2
actually it's a simple question.... I just need to find how many objects do I have in my simple code.....
28th Aug 2017, 6:19 PM
Mohamed Sajjadh
Mohamed Sajjadh - avatar
+ 1
You can use a counter... static int counter= 0; and then in the constructors: counter++;
1st Sep 2017, 8:49 AM
Rosa Mø
Rosa Mø - avatar