Thursday, April 21, 2022

Java Arrays: From Basics to Beyond

 Arrays :
  •  An array is a type of variable that can store multiple values. It is like a list of items but it always contains similar data type values.
  • An array is a data structure in java that can hold one or more values in a single variable.
  •  Array in java is a collection of similar types of values.

Example 1:
  String[] aCarMake = new String[5];
      aCarMake[0] = "BMW";
      aCarMake[1] = "AUDI";
      aCarMake[2] = "TOYOTA";
      aCarMake[3] = "SUZUKI";
      aCarMake[4] = "HONDA";

Example 2:
  String [] aCarMake = {"BMW", "AUDI", "TOYOTA", "SUZUKI", "HONDA"};

Example 3:
package selenium;
public class Java_practise {
public static void main(String[] args) {
//Declaring an Array
String [] aMake = {"BMW", "AUDI", "TOYOTA", "SUZUKI", "HONDA"};

// Calling the Print Array method and passing an Array as a parameter
Print_Array(aMake);
}

//This accepts Array as an argument of type String 
public static void Print_Array(String []array){
                 for(int i = 0;i<=array.length-1;i++){
System.out.println("All the values of an Array ==> " + array[i]);
}
}
}


No comments:

Post a Comment