Java'ya Giriş
Jim White
Java Developer


[] kullanılır// Dizi değişkenini bildir int[] prices;// Değer ata prices = {10, 20, 30, 40};

[] kullanarak:int[] prices = {10, 20, 30, 40};
// İlk elemana erişim
int firstElement = prices[0]; // Değer 10
// İkinci elemana erişim
int secondElement = prices[1]; // Değer 20

int[] prices = {10, 20, 30, 40};// Üçüncü elemanın değerini 95 yapın prices[2] = 95;

int[] itemIDs = {10, 20, 30, 40, 50};
// Olmayan altıncı elemana erişim
itemIDs[5] = 60; // <- Bu bir hataya yol açar
.length özelliğiyle kontrol edinint[] prices = {10, 20, 30, 40};
int pricesLength = prices.length; // Değer 4

Tekil değerleri yazdırabiliriz:
class ArrayElementPrinting {
public static void main (String[] args){
int[] prices = {10, 20, 30, 40};
// Eleman eleman yazdırma
System.out.println(prices[0]);
System.out.println(prices[1]);
}
}
10
20
Tüm diziyi yazdırmak bir gösterim döndürür:
class ArrayPrinting {
public static void main (String[] args){
int[] prices = {10, 20, 30, 40};
// Tümünü yazdırma
System.out.println(prices);
}
}
[I@d041cf
// String dizisi
String[] productNames = {"Organic Honey",
"Cold Brew Coffee",
"Dark Chocolate Bar"};
Strings ile sınırlı değildir
// Bildir ve ata
int[] prices = {10, 20, 30, 40};
// Getir
int secondElement = prices[1];
// Güncelle
prices[1] = 25;
// Uzunluk
// Değer 4
int pricesLength = prices.length;
Java'ya Giriş