Reputation: 271
For example this array has 5 element.
int saffet[] = {0,2,4,6,8};
And this has 2
int saffet[] = {0,2};
How can i get such as above? (question is maybe simple because I'm learning java new)
Upvotes: 0
Views: 80
Reputation: 1499760
Yup, it's easy :)
int length = saffet.length;
Note that it's recommended that you keep the type information together when declaring a variable (or parameter, return type etc) - while your declaration is correct, this is preferred:
int[] saffet = { 0, 2, 4, 6, 8 };
See chapter 10 of the Java Language Specification for more details on arrays.
Upvotes: 3