Premium Only Content

#28 Creation of Array in JAVA | Skyhighes | Lecture 28
There are three main ways to create an array in Java:
1. Declaring and Instantiating:
This is the most common way to create an array. You specify the data type and size of the array, and then allocate memory for it using the new keyword.
Java
int[] numbers = new int[5]; // Creates an array of 5 integers
String[] names = new String[10]; // Creates an array of 10 strings
Use code with caution. Learn more
2. Initializing with Values:
You can directly initialize the array elements with values during creation.
Java
int[] scores = {100, 85, 98, 75, 90}; // Creates an array of 5 initialized integers
String[] days = {"Mon", "Tue", "Wed", "Thu", "Fri"}; // Creates an array of 5 initialized strings
Use code with caution. Learn more
3. Using Array Literal:
Java 10 introduced array literals, which provide a concise way to create and initialize arrays.
Java
int[] ages = [25, 30, 22, 18, 40]; // Creates an array of 5 initialized integers
String[] fruits = ["Apple", "Banana", "Orange", "Mango"]; // Creates an array of 4 initialized strings
Use code with caution. Learn more
Additional Points:
You can access specific elements in an array using their index (starting from 0).
Arrays are dynamically sized, meaning you can define the size during creation.
Java supports multidimensional arrays as well, allowing you to organize data in a table-like format.
Remember, the choice of method depends on your specific needs and preferences.
I hope this clarifies the different ways to create arrays in Java. Feel free to ask if you have any further questions!
-
23:47
JasminLaine
14 hours agoDrake ROASTS Canadian Politician—Danielle Smith OBLITERATES ‘Socialist’ Carney
13.3K17 -
LIVE
Father Russell
3 hours agoDune Awakening | Solo | Into The Deep Desert | PVP Begins
448 watching -
25:28
Fit'n Fire
18 hours ago $1.49 earnedTop 5 LPVO Recommendations June 2025
10.6K -
LIVE
Biscotti-B23
2 hours ago $0.19 earned🔴 LIVE RANKED MATCHES 🏆 ELITE EDITION GIVE AWAY ⚽ REMATCH LAUNCH DAY
86 watching -
LIVE
tacetmort3m
9 hours ago🔴 LIVE 24H - LAST DAY OF 24H STREAMS - DUNE AWAKENING DAY 7
94 watching -
15:26
megimu32
1 day agoPush Pop vs Ring Pop: The Ultimate 90s Candy Showdown!
18.7K13 -
LIVE
Lofi Girl
2 years agoSynthwave Radio 🌌 - beats to chill/game to
357 watching -
LIVE
DimeFS
6 hours agoWARZONE!!!!
60 watching -
1:15:31
TheDozenPodcast
18 hours agoKevin Lane Exclusive after Prison Release | I Thought I’d Die in Jail
16.1K1 -
1:44:58
The Pascal Show
13 hours ago $2.44 earnedMANHUNT UNDERWAY! Cops Search For Vance Boelter! WIFE DETAINED?! Press Conference
14.5K6