Important concept about Arrays Flashcards
- what is an anonoymous Array?
- An ananomous Array is an array without a variable referencing it.
example: new int[] {1,2,3,4,5};
- how do we return array from method?
int[] numbers = {2,3,4,5,6};
return numbers;
- return new int[] {2,3,4,5,6}
// this code does the same thing as the code above
methods used to print array
1.printArrays(); this method print array.
2.toString(); // this method print the string representation of array.
method to fill Array
1.fill(); // this method fill the whole array. example: string[] names = new string[3] // this create an array object in the computer memory.
Arrays.fill( string, “matthew”); // this method fill the array with the value/data matthew.
2.fill(array,fromindex, toindex, value); // this method fill the array at a specific index.
- How to get the sum in an array.
Sum += number[i] // this is how we get the sum of the element in an array.
- How do we get the product of the element in an array.
product *= number[i] // this is how we get the product of the element in an array.
- How do we get the average of the element in an array.
double average = double(sum) / number.length;
- how do we search an array.
if(searchElement == number[i])
// this search the element in an array. and see if searchelement is equal to the element in the array.
- How do we pass object and primitive data to method.
we can pass a primitive and non primitive to a method at the same time.
example: (int[] numbers, int n );