Sunday, 18 December 2022

Java collections - List

 Java collections  

A ) List

 Write a program by using arraylist and Add the number 5,2,2,1,3 and remove 2 number index (1) and arranging the ascending order



import java.util.ArrayList;
import java.util.Collections;

public class simplelist {
    public static void main(String[ ] args) {
        ArrayList<Integer> number = new ArrayList<Integer>();
        number.add(5);
        number.add(2);
        number.add(2);
        number.add(1);
        number.add(3);

        System.out.println(number);
        number.remove(2);
        Collections.sort(number);
        System.out.println(number);
    }
}



OUTPUT: 

[5, 2, 2, 1, 3]

[1, 2, 3, 5]

No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...