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!
-
10:56
Liberty Hangout
2 days agoThank You Charlie
187K48 -
1:49:51
Steve-O's Wild Ride! Podcast
8 days ago $7.01 earnedChet Hanks Found God On Chat GPT | Wild Ride #266
65.7K6 -
2:18:15
Badlands Media
7 hours agoOnlyLands Ep. 25: Erica Kirk Steps Up, Antifa Fallout, and Global Sparks
84K23 -
2:05:01
TimcastIRL
11 hours agoTrump Just Ended H1B Visas In Major Crackdown, Charging $100k Per Visa | Timcast IRL
297K193 -
4:02:20
Nerdrotic
16 hours ago $29.88 earnedKimmel MELTDOWN | Hollywood Boycotts Disney | Friday Night Tights 372 with Kaida
134K21 -
34:08
Bannons War Room
11 hours agoMEGYN KELLY: Jimmy Kimmel and Sore Cultural Losers, and Charlie Kirk's Spiritual Revival, w/ Bannon
97K91 -
59:27
NAG Podcast
11 hours agoBrandon Straka: BOLDTALK with Angela Belcamino
88.2K11 -
59:43
Sarah Westall
9 hours agoVietnam Shuts down 86 Million Bank Accounts, The Fourth Turning & more w/ Andy Schectman
67.3K17 -
1:17:51
Flyover Conservatives
16 hours agoMary Flynn O’Neill and Clay Clark: The Church Must Rise or America Falls | FOC Show
66.3K12 -
3:36:01
I_Came_With_Fire_Podcast
19 hours agoThe Global ANTIFA Connection You've Never Heard Of | The Israel Question
54.2K15