Need of Variable length arguments in java || Understand with examples || varargs

preview_player
Показать описание
Hi, this video covers variable length argument in java.We are going to discover the reason why we need vararg in java.We will start this concept creating a real-time scenario and understanding the problem then we get into the coding.

variable argument lists in java //

Java var-args can be written inside a method argument which can accept a group of elements.This helps us in situations like when we are not sure how many arguments, we should take in a method.

If we take variable length argument as the argument inside a method then the method can handle any number of arguments passed into it.

So we can think, var-args in java is just similar to a one-dimensional array but the basic differences taking an array as a parameter and a var-args as a parameter is :

if we need to pass a method which accepts an array as an argument, then we have to pass an array object inside the method argument while calling the method.( this is the only way to call an array args type method)

we can’t pass elements directly to a method which takes an array as an argument.

But if we use a method which takes, var-args as an argument, then the advantages that we will get is :

we can pass an array object to this method and also we can pass a bunch of elements directly to this method to execute it.

please follow this tutorial for example.

Java interview question on hashcode() and equals() || Java collection interview questions on HASHMAP

Why String is immutable in Java ? || The four reason you must know

Hashmap Internal working

Why we need constructor inside an abstract class ? || Popular Java interview question

Stay tuned and like my Facebook page for more.

Music :
-----------
credits : -
(intro)
1)
Creative Commons — Attribution 3.0 Unported— CC BY 3.0

2)
NCM Epic Music Ender Guney

-----

intro template :
Рекомендации по теме
Комментарии
Автор

I saw your subscribers climbing and dismissed it as maybe they just think you are cute or something, after all there are plenty of channels doing good tutorials. I see why people are liking you tho. You know what you are talking about, and don't seem to get lost at the keyboard interrupting flow. You have attractive, pleasant looking graphics that are easy to read and don't overly distract the viewer. Your delivery is very easy to understand, audibly. You don't sound bored and sleepy, nor do you sound angry or like you drank way too many coffees. Pleasant, highly competent instruction on important topics. Another new subscriber.

jvsnyc
Автор

Task.m1() is correct way to call a static method

madhubabu-hqyc
Автор

You made the coding easy. Lots of love from my side dude !

aravind
Автор

Thnank you soo much avilash.. keep posting videos like this...

shashikumarm.h
Автор

THANKS
public class A9UsingVarargs {


public static void main(String[] args){

A9UsingVarargs obj = new A9UsingVarargs();
int a[] = {10, 20, 30, 40, 50};

obj.add(a);

}


void add(int...numbers){ // accepts an arry of numbers
int result =0;
System.out.println("Inside the add method");
for(int eachX: numbers){
result = result+ eachX ;

}
System.out.println(result);
}


}

whimsicalvibes
Автор

Please make more videos on multithreading and collections

SurajAgarwaladad
Автор

Var Args explanation you made it simple.You explained Array is almost same as ... made it as clear understanding.you 've good creativity in explaining the things with very good examples and subtitles.Great job :).Expecting Multithreading Videos :):):)

raghavendrajamili
Автор

your videos are very useful and you ve explained concepts in very easy way.Sir plz do video for SERIALIZATION IN inheritance and containment.

RadheKrishna-tkjk
Автор

Hey Abhilash, this is a good one... Please make a video on Spring Transaction with depth and suitable use cases...
You just explain so nicely...
Answer of that task is 3 option...

santoshkumarsahoo
Автор

i think 4 dislikers are your relatives bro (:: (:

SimpleProgrammer
Автор

What if we want to pass mix of different types of arguments??

shalushaji
join shbcf.ru