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!
-
37:26
Adam Carolla
7 hours ago $12.30 earnedSchwarzenegger's Dramatic Weight Loss, Newsom's Homeless Plan + Rotisserie Chicken on planes #news
108K19 -
3:38:24
Barry Cunningham
11 hours agoPRESIDENT TRUMP IS USHERING IN A MAGA NEW WORLD ORDER! | LIVE INTERVIEW WITH SEAN HANNITY
138K57 -
7:25:06
SpartakusLIVE
9 hours agoWZ for the GOBLINS
67.8K1 -
2:53:28
TimcastIRL
7 hours agoWoke Judge INDICTED For Aiding Illegal Immigrants, Grand Jury Brings Formal Charges | Timcast IRL
434K125 -
2:07:07
RiftTV/Slightly Offensive
10 hours agoThe SHILOH HENDRIX Debate: Sarah Stock, Jon Miller, Misfit Patriot, Bryson Gray | The Rift Report
81.4K62 -
21:10
Producer Michael
14 hours agoWE CRASHED A MULTI-MILLION DOLLAR MANSION OPEN HOUSE!
46.1K5 -
1:41:55
Anthony Rogers
15 hours agoEpisode 366 - Starseeds, Walk-ins, and ET-Human Hybrids
51.5K6 -
1:45:19
AlaskanBallistics
7 hours ago $3.22 earnedI Love this Gun Podcast #34
45.3K5 -
5:54:10
FusedAegisTV
10 hours ago『NIN lvl 53』Tues R&R | Final Fantasy XIV | Trump lashes out at Big Pharma, IGN top 25 JRPG list
41.3K1 -
1:26:51
Adam Does Movies
14 hours ago $1.44 earnedTuesday Movie Talk Hangout + AMA - LIVE!
33.6K1