Category Archives: ArrayList

Add, Remove, Retain, Sort & other important methods of arraylist in java

Given an arraylist, we would demonstrate the following operations of arraylist. Remove Add Retain Sort Iterate Get Contains And Clear Program – Add, sort, iterate, get methods of arraylist in java package org.learn.collection.list.arrayList; import java.util.ArrayList; import java.util.Collections; import java.util.ListIterator; public class DemoArrayList { public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<>(); arrayList.add(“archery”); arrayList.add(“badminton”);… Read More »

Iterate or loop arraylist collection of String objects/elements in java (example)

ArrayList class is resizable array implementation of the List interface. ArrayList maintains the insertion order of element or string objects. ArrayList allows the duplicate elements & we can randomly access elements by index. ArrayList is not thread safe. If multiple threads access an ArrayList instance concurrently, then arraylist must be synchronized externally. The iterators returned… Read More »

Sort elements of arraylist in java (ascending and descending order)

Given an arraylist of string objects in java. We would like to sort elements of arraylist. Sort elements of arraylist in ascending and descending order. 1.  Sort String objects of arraylist in ascending & descending order (java). package org.learn.collection.list.arrayList; import java.util.ArrayList; import java.util.Collections; public class SortElementInArrayList { public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<>(); arrayList.add(“archery”);… Read More »

Remove or delete elements/nodes/objects from arraylist collection (java/example)

Given an arraylist containing string objects, we would like to remove or delete elements from arraylist collection. Arraylist has following methods to remove or delete element(s)/nodes/objects. Program – remove or delete elements/nodes from arraylist in java package org.learn.collection.list.arrayList; import java.util.ArrayList; public class DemoRemoveInArrayList { public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<>();… Read More »