Java Program to Pass ArrayList as the function argument

To understand this example, you should have the knowledge of the following Java programming topics:


Example 1: Pass ArrayList as Function Parameter

Output

ArrayList: Java, Python, JavaScript,

In the above example, we have created an arraylist named languages. Here, we have a method display(). It prints elements of arraylist.

Notice the line,

display(languages);

Here, we have passed languages as the function parameter.


Example 2: Pass ArrayList as Function Parameter by converting into Array

Output

Marks: [67, 87, 56]
Percentage: 70.0

In the above example, we have created an arraylist named marks. Notice the line,

percentage(marks.toArray(new Integer[0]));

Here, we are passing the arraylist as an argument to the percentage() method.