#30 jagged and 3D Array in Java

  Рет қаралды 124,699

Telusko

Telusko

Күн бұрын

Check out our courses:
Enterprise Java Spring Microservices: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-sp...
Coupon: TELUSKO20 (20% Discount)
Udemy Courses:
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
Java For Programmers:- bit.ly/javaPro...
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
In this lecture we are discussing:
1)What if array of array of different size ?
2)Jagged array concept
3)If i donot know column size of array
4)traverse the array using for loop and enhance loop
#1
Suppose we want to create a 2d dimensional array such that it has
5 rows but we donot know for each row we need different size for column.
for that we go for array of array of different size
-------------
| 1 | 2 | 3 |
---------------------
| 4 | 5 | 6 | 7 | 8 |
-------------------------
| 1 | 5 | 9 | 2 | 4 | 7 |
-------------------------
in above diagram we have three rows and first row has 3 elements
second row has 5 elements and third row has 6 elements.
#2#3
jagged array concept come in java 8
-- Jagged array is a multidimensional array where member arrays are of different size. For example, we can
create a 2D array where first array is of 3 elements, and is of 4 elements. Following is the example demonstrating
the concept of jagged array.
syntax to create --
int nums[][]=new int[3][];
nums[0] =new int[3];
nums[1] =new int[5];
nums[2] =new int[6];
initalize value in array using random()method present in Math class
for(int i=0;i nums.length;i++){
for(int j=0;j nums[i].length;j++){
nums[i][j]=(int)(Math.random()*10);
}
}
#5
Traverse using for loop :
for(int i=0;i nums.length;i++){
for(int j=0;j nums[i].length;j++){
System.out.print(nums[i][j]+" ");
}
}
Traverse using enhanced for loop:
for(int x[]:nums){
for(int y:x){
System.out.println(y);
}
}
Note: Just like 2-d jagged array we can create 3-d , 4-d jagged array
for cursoity:
int num[][][]=new int[3][][];
num[0]=new int[2][];
num[1]=new int[3][];
num[2]=new int[4][];
num[0][0]=new int[2];
num[0][1]=new int[3];
num[1][0]=new int[4];
num[1][1]=new int[5];
num[1][2]=new int[6];
num[2][0]=new int[7];
num[2][1]=new int[8];
num[2][2]=new int[9];
num[2][3]=new int[10];
Intialize the array:
for(int i=0;i num.length;i++){
for(int j=0;j num[i].length;j++){
for(int k=0;k num[i][j].length;k++){
num[i][j][k]=(int)(Math.random()*10);
}
}
}
Traverse the element of array:
for(int i=0;i num.length;i++){
for(int j=0;j num[i].length;j++){
for(int k=0;k num[i][j].length;k++){
System.out.print(num[i][j][k]+" ");
}
}
}
Github repo : github.com/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
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

Пікірлер: 19
@ayashazhar5340
@ayashazhar5340 6 ай бұрын
had a hard time finding a proper video on jagged array and how to update it . thanks bro
@DevilGaming-bl1og
@DevilGaming-bl1og Ай бұрын
In first for loop instead of i
@29balapraveen
@29balapraveen 9 ай бұрын
Can we do jagged array of 2nd dimension in 3 dimensional array?
@IshmaelSmart-l8v
@IshmaelSmart-l8v 4 ай бұрын
I like the way you explain Boss, thanks 😊😊
@anilkumargangarapu01
@anilkumargangarapu01 8 ай бұрын
hii, how can we assign fixed values of our own to arrays with different sizes,
@anilkumargangarapu01
@anilkumargangarapu01 8 ай бұрын
without using random values,
@saikiranreddy3558
@saikiranreddy3558 Ай бұрын
@@anilkumargangarapu01 You have to do it in this way (eg. for 2x3 array): array[0][0] = 23; array[0][1]=19; array[0][2]=53; array[1][0] = 08; array[1][1]=91; array[1][2]=63; i.e, you have to assign values manually :p
@manmohankatyayan5014
@manmohankatyayan5014 Жыл бұрын
sir how can i get notes
@sruthigudmella3322
@sruthigudmella3322 Жыл бұрын
the notes are in the description 😁
@SowjanyaKadiveti
@SowjanyaKadiveti Ай бұрын
i had tried much more complex one three arrays class demo { public static void main(String[] args) { int num[][][]= new int[3][2][]; num[0][0]= new int[10]; num[0][1]= new int[6]; num[1][0]= new int[2]; num[1][1]= new int [5]; num[2][0]=new int[8]; num[2][1]=new int[8]; for(int i=0;i
@lisav9566
@lisav9566 10 ай бұрын
Thanks!
@AdhilMhmdVK
@AdhilMhmdVK Жыл бұрын
Three dimensional array with proper example...i couldnt understand this one.
@pranavsharma5395
@pranavsharma5395 Жыл бұрын
thug life of telusko
@puruagni1927
@puruagni1927 5 ай бұрын
Why are you not updating VS Code? Please update VS Code.
@thelivereactions
@thelivereactions 7 ай бұрын
This video cant understand , where does math & *10 come from!
@Bjorn-vh2px
@Bjorn-vh2px 5 ай бұрын
// Math is used for generating random numbers And *10 used for multiplying those number. Once watch his two dimensional array video 👍
@purnimanaskar2671
@purnimanaskar2671 8 ай бұрын
// Online Java Compiler // Use this editor to write, compile and run your Java code online public class Demo { public static void main(String[] args) { int nums[][][]=new int [3][4][5]; // three dimensional for(int i=0;i
@dashtech1387
@dashtech1387 6 ай бұрын
Not understand
@RameshMaity90
@RameshMaity90 5 ай бұрын
public class Array { public static void main(String[] args) { int num1[]=new int[3]; int num[][]=new int[3][4]; for(int i=0;i
#31 Drawbacks of Array in Java
2:50
Telusko
Рет қаралды 85 М.
#29 Multi Dimensional Array in Java
13:08
Telusko
Рет қаралды 167 М.
Хасанның өзі эфирге шықты! “Қылмыстық топқа қатысым жоқ” дейді. Талғарда не болды? Халық сене ме?
09:25
Демократиялы Қазақстан / Демократический Казахстан
Рет қаралды 300 М.
#32 Array of Objects in Java
8:52
Telusko
Рет қаралды 148 М.
Array vs. ArrayList in Java Tutorial - What's The Difference?
17:36
Coding with John
Рет қаралды 536 М.
#53 Packages in Java
12:20
Telusko
Рет қаралды 204 М.
Arrays In Java Tutorial #10
9:26
Alex Lee
Рет қаралды 457 М.
#40 Encapsulation in Java
11:42
Telusko
Рет қаралды 186 М.
Java 2D arrays 🚚
8:06
Bro Code
Рет қаралды 177 М.
#26 Stack And Heap in Java
12:37
Telusko
Рет қаралды 262 М.
Multithreading in Java Explained in 10 Minutes
10:01
Coding with John
Рет қаралды 935 М.
2D Array Java Tutorial #11
8:34
Alex Lee
Рет қаралды 347 М.