Menu

1 / 3

Types of Array in Java

DEV Community: java·Rakshambika·9 days ago
#fOF5DERd
#devtojava#devto#dev#array#enter
Long article (388 words) — no AI summary yet.
Reading 0:00
15s threshold

Types of array:

Single-Dimensional Array

Multi-Dimensional Array

One-Dimensional Array :

A one-dimensional array is used to store multiple values of the same data type in a single row.

It uses a single index to access the elements.

Syntax:

dataType [ ] arrayName = { value1 , value2 , value3 } ;

Enter fullscreen mode

Exit fullscreen mode

Example:

public class OneD_Array {

public static void main ( String [ ] args ) {

int [ ] numbers = { 10 , 20 , 30 , 40 , 50 } ;

System . out . println ( numbers [ 0 ] ) ; System . out . println ( numbers [ 1 ] ) ; System . out . println ( numbers [ 2 ] ) ; } }

Enter fullscreen mode

Exit fullscreen mode

Output:

10 20 30

Enter fullscreen mode

Exit fullscreen mode

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.