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!
-
29:53
MYLUNCHBREAK CHANNEL PAGE
1 day agoUnder The Necropolis - Pt 1
61.8K22 -
2:00:10
Bare Knuckle Fighting Championship
3 days agoCountdown to BKFC on DAZN HOLLYWOOD & FREE LIVE FIGHTS!
28.3K2 -
2:53:01
Jewels Jones Live ®
1 day agoA MAGA-NIFICENT YEAR | A Political Rendezvous - Ep. 103
40.5K16 -
29:54
Michael Franzese
7 hours agoCan Trump accomplish everything he promised? Piers Morgan Article Breakdown
67.7K43 -
2:08:19
Tactical Advisor
11 hours agoThe Vault Room Podcast 006 | Farwell 2024 New Plans for 2025
152K11 -
34:12
inspirePlay
1 day ago $4.64 earned🏆 The Grid Championship 2024 – Cass Meyer vs. Kelly Rudney | Epic Battle for Long Drive Glory!
60.2K8 -
17:50
BlackDiamondGunsandGear
9 hours ago $1.18 earnedTeach Me How to Build an AR-15
36.4K4 -
9:11
Space Ice
1 day agoFatman - Greatest Santa Claus Fighting Hitmen Movie Of Mel Gibson's Career - Best Movie Ever
99.6K42 -
42:38
Brewzle
1 day agoI Spent Too Much Money Bourbon Hunting In Kentucky
65.3K12 -
1:15:30
World Nomac
17 hours agoMY FIRST DAY BACK in Manila Philippines 🇵🇭
49.5K9