#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:34
MinuteTutor
1 year agoArrays in Java For Beginners
4 -
9:46
Programming Tutorials
1 year agoLearn Java Tutorial for Beginners, Part 10: Arrays
3 -
13:06
Programming Tutorials
1 year agoLearn Java Tutorial for Beginners, Part 12: Multi-dimensional Arrays
7 -
8:39
Programming Tutorials
1 year agoLearn Java Tutorial for Beginners, Part 11: Arrays of Strings
7 -
3:57
DrOfEng
2 months agoCreating Objects, Instantiation, Constructors, Classes, Java - AP Computer Science A
5 -
6:20
Quentis
1 year agoJava beginners #8: arrays
5 -
11:28
Coding With John
8 months agoStatic vs Non-Static Variables and Methods In Java - Full Simple Tutorial
24 -
5:00
sdeepak
6 years agoJava tutorial
94 -
4:12
ComputerScienceVideos
1 year agoPROGRAMMING IN C++ / X-Code || Tutorial 34 - Array of Structures
1 -
3:08
AHMEDKAZEKA97
1 year agoBeginning Java Programming Course for AP Computer Science
180