/*
In java, you can create an array like this:
new int[]{1, 2, 3};
replace `int` with whatever you want
*/
public static void doSomething(int[] list) {
System.out.println("Something is done.");
}
public static void main(String[] args) {
doSomething(new int[]{1, 2, 3});
}
/*Passing Array to Method , tow ways to passing 1: with method name, 2: passing Anonymous Array
Means -> array can be invoking by passing an initialized array element to the method.*/
/* first method */
public class PassArray {
// creating method and receiving array as parameter
static void MethodName(double[] array) {
// foreach loop for printing array elements
for (double element : array) {
System.out.println(element);
}
}
public static void main(String[] args) {
// Declaring and Initializing an array
double[] A = { 1.1, 2.4, 4.5, 5.9 };
MethodName(A);// passing array to method
}
}
/* Second method*/
public class PaasArrToMth {
static void MethodName(int[] array) {
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
}
public static void main(String[] args) {
// Anonymous array means without name
MethodName(new int[] { 3, 1, 2, 6, 4, 2 });// passing anonymous array to method
// don't need to declare the array while passing an array to the method.
}
}
methodName(new int[]{1, 2, 3}); // Replace int for different types
public int min(int [] array) {
int min = array[0];
for(int i = 0; i<array.length; i++ ) {
if(array[i]<min) {
min = array[i];
}
}
return min;
}
int minimum = min(myArray)
Code Example |
---|
Java :: parcourir un string java |
:: how to convert 2d to 1d array in java |
Java :: spiral traversal of matrix leetcode |
:: |
:: |
:: |
:: |
Java :: |
:: color class android |
:: select list of values from db java |
Java :: java letter to number |
:: java map tostring |
:: android gridview item click effect ripple |
:: java easy list |
:: deifine an integer array in java |
Java :: |
:: locked screen android studio |
:: |
Java :: Java Add Elements to an ArrayList |
Java :: |
:: arraylist<hashmap<string, string arraylist = new arraylist<() |
Java :: |
:: java run class file |
Java :: |
Java :: java noverify |
Java :: spring security antmatchers id |
Java :: prime factorization java |
Java :: |
Java :: is c# similar to java |
:: |