January 23, 2018

To remove a value from arraylist without iterating

/**
 * To remove a primitive data type for an Arraylist
 * without out iterating all the elements
 */
package com.belazy.generics;

import java.util.ArrayList;
import java.util.List;

/**
 * @author belazy
 *
 */
public class ArrayListRemoveSample {

/**
* @param args
*/
public static void main(String[] args) {

List<Integer> numberList = new ArrayList<Integer>();
numberList.add(1);
numberList.add(11);
numberList.add(2018);
numberList.add(911);
numberList.add(25);

System.out.println("--- before ---");
for(Integer thisNumber : numberList){
System.out.print(" "+thisNumber+" ");
}


numberList.remove(new Integer(911));

System.out.println("\n--- After ---");
for(Integer thisNumber : numberList){
System.out.print(" "+thisNumber+" ");
}
}

}

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments