Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

arraylist remove value in java

// Given a list of Integers 1, 2, 3, 4, 5, 6 ....etc. remove all values greater than 100.
    public static void main(String[] args) {

ArrayList<Integer>list1=new ArrayList<>(Arrays.asList(1,2,3,50,70,80,120,150,200));
        ArrayList<Integer>list2 = new ArrayList<>();
        for(int each : list1)
            if(each<100)
                list2.add(each);

            list1 = list2;
        System.out.println(list1); // [1, 2, 3, 50, 70, 80]
    }
 
PREVIOUS NEXT
Tagged: #arraylist #remove #java
ADD COMMENT
Topic
Name
3+3 =