import java.util.*; public class RemoveDuplicates { public static List removeDuplicates(List sortedList) { // Create a new list to store unique elements List uniqueList = new ArrayList<>(); for (int i = 0; i < sortedList.size(); i++) { // Add the element to the unique list if it is the first element // or if it is different from the previous element if (i == 0 || !sortedList.get(i).equals(sortedList.get(i - 1))) { uniqueList.add(sortedList.get(i)); } } return uniqueList; } public static void main(String[] args) { List sortedList = Arrays.asList(1, 2, 2, 3, 3, 3, 4, 4); List result = removeDuplicates(sortedList); System.out.println("Input List: " + sortedList); System.out.println("List After Removing Duplicates: " + result); } }