cari lokasi index array di java menggunakan nilai datanya

gunakan script

Arrays.asList(namaArray).indexOf(nilai);

berikut contohnya :

public class ArrayCariIndex {
public static void main(String[] args) {
Integer[] angka = new Integer[5];
angka[0] = 40;
angka[1] = 23 ;
angka[2] = 54 ;
angka[3] = 12 ;
angka[4] = 42 ;
System.out.println(“cari lokasi angka 12”);
System.out.println(“ada di indeks ke- “+Arrays.asList(angka).indexOf(12));
}
}

hasilnya akan diketahui bahwa angka 12 terletak di array indeks ke-3

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s