java array index code example

Example 1: how to initialize an array in java

int[] data = {10,20,30,40,50,60,71,80,90,91};
// or
int[] data;
data = new int[] {10,20,30,40,50,60,71,80,90,91};
// or
int[] data = new int[10];
data = {10,20,30,40,50,60,71,80,90,91};

Example 2: array java

int[] intArray = new int[20];
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

Example 3: java indexof array

java.util.Arrays.asList(theArray).indexOf(o)

Example 4: arrays

// Java program to demonstrate working of Arrays.toString() 
import java.io.*; 
import java.util.*; 

class GFG { 
	public static void main(String[] args) 
	{ 
		// Let us create different types of arrays and 
		// print their contents using Arrays.toString() 
		boolean[] boolArr = new boolean[] { true, true, false, true }; 
		byte[] byteArr = new byte[] { 10, 20, 30 }; 
		char[] charArr = new char[] { 'g', 'e', 'e', 'k', 's' }; 
		double[] dblArr = new double[] { 1, 2, 3, 4 }; 
		float[] floatArr = new float[] { 1, 2, 3, 4 }; 
		int[] intArr = new int[] { 1, 2, 3, 4 }; 
		long[] lomgArr = new long[] { 1, 2, 3, 4 }; 
		Object[] objArr = new Object[] { 1, 2, 3, 4 }; 
		short[] shortArr = new short[] { 1, 2, 3, 4 }; 

		System.out.println(Arrays.toString(boolArr)); 
		System.out.println(Arrays.toString(byteArr)); 
		System.out.println(Arrays.toString(charArr)); 
		System.out.println(Arrays.toString(dblArr)); 
		System.out.println(Arrays.toString(floatArr)); 
		System.out.println(Arrays.toString(intArr)); 
		System.out.println(Arrays.toString(lomgArr)); 
		System.out.println(Arrays.toString(objArr)); 
		System.out.println(Arrays.toString(shortArr)); 
	} 
}

Example 5: java array get index

public int getArrayIndex(int[] arr,int value) {

        int k=0;
        for(int i=0;i<arr.length;i++){

            if(arr[i]==value){
                k=i;
                break;
            }
        }
    return k;
}

Example 6: arrays

//Javascript Array
var fruitList = ["Bananas", "Apples", "Oranges"]

Tags:

Misc Example