- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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 to create an Array in Java?
In Java, you can create an array just like an object using the new keyword. The syntax of creating an array in Java using new keyword −
type[] reference = new type[10];
Where,
- type is the data type of the elements of the array.
- reference is the reference that holds the array.
And, if you want to populate the array by assigning values to all the elements one by one using the index −
reference [0] = value1; reference [1] = value2;
For example, if you want to create an integer array of 5 elements you can create it using new keyword −
int[] myArray = new int[5]; You can populate the array element by element using the array index: myArray [0] = 101; myArray [1] = 102; You can also create and initialize an array directly using the flower brackets ({}). int [] myArray = {10, 20, 30, 40, 50}
- Related Articles
- How to create an ArrayList from an Array in Java?
- How to create an array of Object in Java
- How to create an array of linked lists in java?
- How to create LabelValue Tuple from an array in Java
- How to declare, create, initialize and access an array in Java?
- How to create a constructor reference for an array in Java?
- How to create an array in PowerShell?
- How to create a generic array in java?
- How to create array of strings in Java?
- Create Ennead Tuple from an array in Java
- Create KeyValue Tuple from an array in Java
- Create Decade Tuple from an array in Java
- Create Octet Tuple from an array in Java
- How to create an empty array in Kotlin?
- How to create an empty array in Swift?

Advertisements