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!
-
2:12:41
TheSaltyCracker
10 hours agoMSM Implodes After Trump Win ReeEEeE Stream 11-17-24
203K414 -
4:31
SLS - Street League Skateboarding
10 days agoFuna Nakayama 3rd Place at SLS Sydney 2024 | Best Tricks
63.7K7 -
2:15:24
vivafrei
19 hours agoEp. 236: BARNES IS BACK! Election Recap! Trump Nominees! Trump Persecutions - Wha's Next? & MORE!
235K232 -
6:25:47
SynthTrax & DJ Cheezus Livestreams
18 hours agoDJ Cheezus & DEF JAM Fight for NY on PS2 - Hip Hop Violence and Vibes (1pm PST / 4pm EST)
94.1K4 -
2:01:47
Nerdrotic
13 hours ago $14.15 earnedEgypt, Peru and Guatemala Luke Caverns RETURNS! | Forbidden Frontier #082
81K10 -
LIVE
Vigilant News Network
13 hours agoFDA Approves Trials for New “Pandemic” Vaccine | Media Blackout
1,929 watching -
4:06:21
GamerGril
14 hours agoIM THE GREASTEST OF ALL TIME AT.... CHAOS | DAYS GONE
120K12 -
3:00:18
Due Dissidence
1 day agoTHE PEOPLE VS NATURE by Kevin Augustine - plus a talkback w/ Jimmy Dore
138K22 -
6:02:06
Rotella Games
20 hours agoMake the Hood Great Again | Day 3 | GTA San Andreas
91.5K6 -
2:50:48
PudgeTV
20 hours ago🟡 Practical Pudge Ep 48 with "Willie Faulk" | Catching Up With Old Friends
79.7K3