#28 Creation of Array in Java
361K views on YouTube
Check out our courses:
Agentic AI Engineering with Python : https://go.telusko.com/agentic-ai-python
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : https://go.telusko.com/learn-master
Coupon: TELUSKO10 (10% Discount)
For More Queries WhatsApp or Call on : +919008963671
website : https://telusko.com/
Udemy Courses:
Java Spring:- https://go.telusko.com/Udemyjavaspring
Java:- https://go.telusko.com/udemyteluskojava
Spring: https://go.telusko.com/udemyteluskospring
Java For Programmers:- https://go.telusko.com/javaProgrammers
Python : https://go.telusko.com/udemyteluskopython
Git : https://go.telusko.com/udemyteluskogit
Docker : https://go.telusko.com/udemyteluskodocker
Instagram : https://www.instagram.com/navinreddyofficial/
Linkedin : https://in.linkedin.com/in/navinreddy20
WhatsApp : https://go.telusko.com/whatsapp
Discord : https://discord.gg/D8hWe9BqfF
In this lecture we are discussing:
1)How many way to create array in java?
2)default value store when we creating array with object notation
3) fetching the value assign different value array element
#1
Ways to create array in java
a)Literal notation
Literal notation: int[] arr = {1, 2, 3};
b)Object notation
Array constructor: int[] arr = new int[]{1, 2, 3}; // this is not literal notation ,this is object notation with assignment of value
Array constructor with size: int[] arr = new int[3]; arr[0] = 1; arr[1] = 2; arr[2] = 3; //in this we manually assign value but by default 0 is assign in this case
#2
default value which store array when we create using object notation for primitive datatype.
— When you create an array of primitive data types in Java using the object notation, the default value stored in the array depends on the data type:
— int arrays: default value is 0
— boolean arrays: default value is false
— char arrays: default value is ‘\u0000’ (null character)
— byte, short, long arrays: default value is 0
— float arrays: default value is 0.0f
— double arrays: default value is 0.0d
code for you —
char ch[]=new char[3]; //declaration and initialization
for(int i=0;i less then ch.length;i++){
System.out.println(ch[i]);
}
check result–
#4
fetching the element of array :
— for traversing whole array, you need to know either length of array or know length property of array
— using length property we get length of array
— using index we can fetch all value of array
suppose we create int nums[]={2,3,4,5};
access first element then nums[0],
access second element nums[1],
access third element nums[2],
access fourth element nums[3];
— if you match pattern for accessing the element
you get nth element is nums[n-1];
for 7th element nums[7-1]; i.e is nums[6]
— in array position start from 0,1,2, go till n-1 if n is length of array
change value of given position
int nums[]={2,3,4,5};
for(int i=0;i less then nums.length;i++){
System.out.println(nums[i]);
} //traversing whole array — means fetching all elements of array
nums[0]=10;
nums[1]=11;
nums[2]=22;
nums[3]=33;
for(int i=0;i less then nums.length;i++){
System.out.println(nums[i]);
}
Github repo : https://github.com/navinreddy20/Javacode.git
More Learning :
Java :- https://bit.ly/3x6rr0N
Python :- https://bit.ly/3GRc7JX
Django :- https://bit.ly/3MmoJK6
JavaScript :- https://bit.ly/3tiAlHo
Node JS :- https://bit.ly/3GT4liq
Rest Api :-https://bit.ly/3MjhZwt
Servlet :- https://bit.ly/3Q7eA7k
Spring Framework :- https://bit.ly/3xi7buh
Design Patterns in Java :- https://bit.ly/3MocXiq
Docker :- https://bit.ly/3xjWzLA
Blockchain Tutorial :- https://bit.ly/3NSbOkc
Corda Tutorial:- https://bit.ly/3thbUKa
Hyperledger Fabric :- https://bit.ly/38RZCRB
NoSQL Tutorial :- https://bit.ly/3aJpRuc
Mysql Tutorial :- https://bit.ly/3thpr4L
Data Structures using Java :- https://bit.ly/3MuJa7S
Git Tutorial :- https://bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20