Arrays in Java

Arrays are a way to store multiple values in a single variable. In Java, arrays are objects that can be used to store values of the same type, such as integers or strings.

To access the size of an array in Java, you can use the "length" property which is a member of the array object. In the following example code, we create an array of integers and use a for loop to print out each value in the array:

java
public class Main { public static void main(String args[]) { int arr[] = {10, 20, 30, 40, 50}; for(int i=0; i < arr.length; i++) { System.out.print(" " + arr[i]); } } }

When this program is run, it will output:

10 20 30 40 50

Overall, this program demonstrates how to create and use arrays in Java. The "arr.length" property is used to access the size of the array, and a for loop is used to iterate over each element in the array and print it to the console.

Previous Post Next Post