#28 Creation of Array in Java

  Рет қаралды 126,326

Telusko

Telusko

Жыл бұрын

Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-live-weekend
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-spring-cloud
Udemy Courses:
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
Java For Programmers:- bit.ly/javaProgrammers
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusko.com/
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 : github.com/navinreddy20/Javac...
Java:- bit.ly/JavaUdemyTelusko
Spring:- bit.ly/SpringUdemyTelusko
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com

Пікірлер: 15
@justdevi
@justdevi 11 ай бұрын
just a mention, int nums[ ] = new int[4]; is C style array declaration. java style is int[ ] nums = new int[4]; Both are correct btw
@ppganesh7822
@ppganesh7822 10 ай бұрын
It is not possible in c
@AnuragRawat01
@AnuragRawat01 10 ай бұрын
Nah buddy int nums[ ] = new int [4] that can't work in c
@serrioton1858
@serrioton1858 7 ай бұрын
thanks i was confusedf
@newmoviesthamizhantech2663
@newmoviesthamizhantech2663 6 ай бұрын
​@@serrioton1858😂
@wajdwael8775
@wajdwael8775 3 ай бұрын
Thank you for this clear explanation.
@laylachisom8996
@laylachisom8996 Жыл бұрын
Super helpful
@princeiiolaguera921
@princeiiolaguera921 6 ай бұрын
please add exercises thank you
@ricotabaque8705
@ricotabaque8705 Жыл бұрын
how to create new array as user input as identifier array ?
@RameezKhalil-pn4yo
@RameezKhalil-pn4yo Жыл бұрын
You can create a for loop and then for each iteration you can store the value being passed at each index , for example: int arr[i]= sc.nextInt() // you will need to create an object from scanner class, so you can make use of it.
@mso_studio_official
@mso_studio_official Ай бұрын
public static void main(String[] args) { int a[] = {1,2,3,4,5}; for(int i : a){ System.out.println(i); } }
@MadhukumarAp
@MadhukumarAp Жыл бұрын
i have question why index value start with zero.
@RameezKhalil-pn4yo
@RameezKhalil-pn4yo Жыл бұрын
Because that's how the memory structure works, and this is how the compiler interprets the value from the actual indexes. The values are placed over contagious locations with respect to each other so the next index gets calculated via (arr+i); for first element ( arr + 0) provides us with the first element; the list goes on until the last element
@The_Motobikers_World
@The_Motobikers_World Жыл бұрын
And there is one reason for this naming convention is in array the index start from zero because here we calculating how far the element is from beginning of the array , the first element of an array is 0 position far from starting the second element is 1 position far from beginning of the array that's why the index value in many programming language's compiler starting from 0 .
@ramakrishnanalluri2547
@ramakrishnanalluri2547 2 ай бұрын
.
#29 Multi Dimensional Array in Java
13:08
Telusko
Рет қаралды 128 М.
#26 Stack And Heap in Java
12:37
Telusko
Рет қаралды 204 М.
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 33 МЛН
He sees meat everywhere 😄🥩
00:11
AngLova
Рет қаралды 11 МЛН
Happy 4th of July 😂
00:12
Pink Shirt Girl
Рет қаралды 32 МЛН
OMG🤪 #tiktok #shorts #potapova_blog
00:50
Potapova_blog
Рет қаралды 18 МЛН
#24 Methods in Java
11:30
Telusko
Рет қаралды 181 М.
#83 User Input using BufferedReader and Scanner in Java
11:48
#95 Comparator vs Comparable in Java
15:43
Telusko
Рет қаралды 151 М.
#60 Wrapper Class in Java
8:08
Telusko
Рет қаралды 154 М.
#53 Packages in Java
12:20
Telusko
Рет қаралды 160 М.
#40 Encapsulation in Java
11:42
Telusko
Рет қаралды 144 М.
Functional Interface | Lambda Expression in Java
13:56
Telusko
Рет қаралды 138 М.
#42 This keyword in Java
9:45
Telusko
Рет қаралды 111 М.
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 8 МЛН
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 160 М.
When you have 32GB RAM in your PC
0:12
Deadrig Gaming
Рет қаралды 2,1 МЛН
Спутниковый телефон #обзор #товары
0:35
Product show
Рет қаралды 2,2 МЛН