int[] marks = {88, 74, 91, 82, 68, 94};
int marks1 = 88;
int marks2 = 74;
int marks3 = 91;
int marks4 = 82;
int marks5 = 68;
int marks6 = 94;
int[] marks = {88, 74, 91, 82, 68, 94};
int[] numbers = {10, 20, 30};
System.out.println(marks[0]); // Output: 10
System.out.println(marks[2]); // Output: 30
int[] numbers = new int[5]; // Size = 5
// numbers[5] = 10; // ❌ Error, index out of bounds
int[] numbers = {10, 20, 30}; // Only int values allowed
// numbers[0] = 5.5; // ❌ Error, cannot store double
int[] marks = {88, 74, 91, 82, 68, 94};
String[] names = {"Amit", "Bhupinder", "Deepak", "Kamal", "Rahul", "Ravi"};
int[] marks = {88, 74, 91, 82, 68, 94};
String[] names = {"Amit", "Bhupinder", "Deepak", "Kamal", "Rahul", "Ravi"};
Student[] std = {new Student(), new Student()};
for (int i = 0; i < marks.length; i++)
{
System.out.println(marks[i]);
}
for (String name : names)
{
System.out.println(name);
}
System.out.println(marks[2]); // Output: 91
names[1] = "Harpreet"; // Changes "Bhupinder" to "Harpreet"
Person[] people = {new Person("Deepak"), new Person("Rahul")};
// Directly access object methods without casting
System.out.println(people[0].getName()); // Output: Deepak
int[] numbers = new int[5];
// You cannot add a 6th element; need to create a new array
int[] numbers = {10, 20, 30}; // Cannot add a string here
int[] numbers = {10, 20, 30, 40};
// To delete 20, shift 30 and 40 left
numbers[1] = numbers[2]; // numbers becomes {10, 30, 30, 40}
numbers[2] = numbers[3]; // numbers becomes {10, 30, 40, 40}
int[] numbers = new int[10]; // Array can hold 10 elements
numbers[0] = 5;
numbers[1] = 10;
// Only 2 elements are used, but memory for 10 is reserved
int[] numbers = {10, 20, 30};
int[][] matrix = {{1,2}, {3,4}};
int[][] jagged = {{1,2,3}, {4,5}, {6}};
int[] marks = {88, 74, 91, 82, 68, 94};
System.out.println(marks[0]); // Output: 88
length
property.
int[] marks = {88, 74, 91, 82, 68, 94};
System.out.println(marks.length); // Output: 6
int[] marks = {88, 74, 91, 82, 68, 94};
System.out.println("Last index position : "+marks.length - 1); // Output: 5
System.out.println("Last Element : "+marks[marks.length - 1]); // Output: 94
char[] letters = {'A', 'B', 'C'};
String[] names = {"Deepak", "Rahul", "Kamal"};
Person[] people = {new Person(), new Person()};
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
We’re here to make our tutorials better based on your thoughts and suggestions.