Fixed number of values of same data type. Syntax: datatype nameOfVariable[] = new dataType[size];
- int[] arr = new int[size];
- int []arr = new int[size];
- int arr[] = new int[size];
int arr[] = new int[5]; => Indexes are always start from 0; => ith index = arr[i]
Access first and last elements: arr[0] & arr[n-1]
Note: There are not heterogeneous arrays in java.
- Properties:
-
int arr[] = new int[5]; Ex: System.out.print(arr.length); //5
-
By default all the elements are initialized with 0;
Ex:
-
for(int i=0; i< arr.length; i++){ System.out.println(arr[i]); } output: 0 0 0 0 0
-
float arr[] = new float[5]; for(float i=0; i< arr.length; i++){ System.out.println(arr[i]); } output: 1.0 2.0 3.0 4.0 5.0
-
double arr[] = new double[5]; for(double i=0; i< arr.length; i++){ System.out.println(arr[i]); } output: 1.0 2.0 3.0 4.0 5.0
Note: Java cannot have negative indexing as it will throw error.
Sum of 1D Array elements with user input

Product Of Elements In 1D Array

Copy The 1D Array into Output Array

TemperatureDifferenceInOneDArray

SwappingOfTwoElements In One Dimension Array

ReverseAPartOfArray In One Dimension Array

FrequencyOfElements In One Dimension Array

OddNegativeIncrement In Dynamic Array

Max Occurrence of character in a String













