Java परिचय
Jim White
Java Developer


[] का उपयोग करें// Declare array variable int[] prices;// Assign value prices = {10, 20, 30, 40};

[] का उपयोग:int[] prices = {10, 20, 30, 40};
// Accessing first element
int firstElement = prices[0]; // Value is 10
// Accessing second element
int secondElement = prices[1]; // Value is 20

int[] prices = {10, 20, 30, 40};// तीसरे element की value 95 करें prices[2] = 95;

int[] itemIDs = {10, 20, 30, 40, 50};
// छठा element नहीं है फिर भी access करना
itemIDs[5] = 60; // <- इससे error आएगा
.length property से array की length जाँचेंint[] prices = {10, 20, 30, 40};
int pricesLength = prices.length; // Value is 4

हम individual values print कर सकते हैं:
class ArrayElementPrinting {
public static void main (String[] args){
int[] prices = {10, 20, 30, 40};
// Printing element by element
System.out.println(prices[0]);
System.out.println(prices[1]);
}
}
10
20
पूरे array को print करने पर representation आता है:
class ArrayPrinting {
public static void main (String[] args){
int[] prices = {10, 20, 30, 40};
// Printing whole thing
System.out.println(prices);
}
}
[I@d041cf
// Array of Strings
String[] productNames = {"Organic Honey",
"Cold Brew Coffee",
"Dark Chocolate Bar"};
Strings तक सीमित नहीं
// Declare and assign
int[] prices = {10, 20, 30, 40};
// Retrieve
int secondElement = prices[1];
// Update
prices[1] = 25;
// Length
// Value is 4
int pricesLength = prices.length;
Java परिचय