What is an anonymous array ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

19th Dec 2016, 3:59 PM
DineshChandra
1 Answer
+ 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; } }
19th Dec 2016, 4:51 PM
Ousmane Diaw