+ 1
What is an anonymous array ?
I think do it present in the java ,and I am not sure about it,and who it really helps
1 Respuesta
+ 1
it is good to use anonymous arrays if you've got a small set of values to fill the array with and also you only wish to use the array in one place and nowhere else similar to an anonymous method. for example:
public class Example{
public static void main(String[] args){
int totalSum = sumArrayNumbers(new int[]{1,2,3,4,6,8,23,34}); // anonymous array
System.out.print(totalSum); // print totalSum
}
public static int sumArrayNumbers(int[] array){
// adds every number within the array and returns it
int totalSum = 0;
for(int i = 0; i < array.length; i++){
totalSum += array[i];
}
return totalSum;
}
}