Q:

What is the output of the following program? arraylist in java

0

What is the output of the following program?

package arrayex;

import java.util.ArrayList;
import java.util.Arrays;
public class ArrayEx 
{
    public static void main(String[] args) {
        ArrayList<String> carList= new ArrayList<String>();
        carList.add("Nissan");
        carList.add("Mercedes");
        carList.add("BMW");
        carList.add(1, "Toyota");
        carList.add("Chevrolet");
        System.out.println("There are " + carList.size() + " cars.");
        System.out.println("List of car names (another way) : ");
        for (String car : carList) 
            System.out.printf("%s ", car);
        System.out.println("\n");
        int[] carModel = {2022, 2016, 2020, 2017, 2019};
        int[] copyModel = new int[carModel.length];

        call_V_R(carModel[3], carModel);
        Arrays.sort(carModel);
        System.out.print("Models are: ");
        for (int i = 0; i < carModel.length; i++)
            System.out.printf("%s  ", carModel[i]);
            System.out.println();
            System.arraycopy(carModel, 0, copyModel, 0, carModel.length);
            System.out.println("is carModel = copyModel? " +
                                Arrays.equals(carModel, copyModel));
    } 
    public static void call_V_R(int carElement, int[] carArray) {
        carElement = 2021;      carArray[0] = 2015;
    }
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

output:

----------

There are 5 cars.

List of car names (another way) : 

Nissan Toyota Mercedes BMW Chevrolet 

Models are: 2015  2016  2017  2019  2020  

is carModel = copyModel? true

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Computer Programming-2 (CS2301) java examples Pass by Value, Pass by Reference , Arrays class and ArrayList

Similar questions


need a help?


find thousands of online teachers now
java book management system using ArrayList... >>