- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I declare and initialize an array in Java?
You can declare an array just like a variable −
int myArray[];
You can create an array just like an object using the new keyword −
myArray = new int[5];
You can initialize the array by assigning values to all the elements one by one using the index −
myArray [0] = 101; myArray [1] = 102;
You can access the array element using the index values −
System.out.println("The first element of the array is: " + myArray [0]); System.out.println("The first element of the array is: " + myArray [1]); Alternatively, you can create and initialize an array using the flower braces ({ }): Int [] myArray = {10, 20, 30, 40, 50}
- Related Articles
- How to declare, create, initialize and access an array in Java?
- how can I declare an Object Array in Java?
- How do we initialize an array within object parameters in java?
- How do you declare, initialize and access jagged arrays in C#?
- How to initialize an array in Java
- How to declare an Array Variables in Java?
- How do I declare a 2d array in C++ using new
- How do I reverse an int array in Java
- How to declare and initialize a dictionary in C#?
- How to declare and initialize a list in C#?
- How to declare and initialize constant strings in C#?
- How do I declare a two-dimensional array in C++ using new?
- How to initialize an array in JShell in Java 9?
- How to initialize an array using lambda expression in Java?
- How do I add an element to an array list in Java?

Advertisements