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!
-
LIVE
Lofi Girl
2 years agoSynthwave Radio 🌌 - beats to chill/game to
1,834 watching -
2:32:02
Side Scrollers Podcast
16 hours agoPirateSoftware Situation, Twitch BANS mang0, “White Man Bad” CRASH OUT | Side Scrollers Live
37.1K6 -
14:17
GritsGG
12 hours agoCopy Our Strategy We Use to Win & Instantly Improve!
559 -
30:44
The Pascal Show
7 hours ago $0.01 earned‘I Was a Regular at the Freak Offs!’ — Adult Star Testifies in Diddy Trial
1.76K1 -
1:38:21
TruthStream with Joe and Scott
1 day agoC R Stewart Author of the Britfield book series live 6/26 3pm pacific 6pm Eastern
5.45K1 -
2:03:51
Inverted World Live
7 hours agoHypersonic Orbs Over New York | Ep. 66
71.4K25 -
3:09:47
TimcastIRL
8 hours agoGOP Rep Demands Citizenship STRIPPED From Dems Zohran Mamdani, NYC Mayor | Timcast IRL
425K241 -
1:21:31
Man in America
12 hours agoTech CEO Exposes the Diabolical Plan to ENSLAVE Us Through Smartphones
42.6K30 -
9:53
MattMorseTV
15 hours ago $18.51 earnedCNN just made a FATAL MISTAKE.
47.2K54 -
3:38:20
Alex Zedra
6 hours agoLIVE! Playing CoD
25.3K5