Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsSwapExample2 { public static void main (String[] args) { //Create a list with items List
list = Arrays.asList(44, 55, 99, 77, 88, 66); System.out.println("List before swapping: "+list); Collections.swap(list, 2, 5); System.out.println("List after swapping: "+list); } }
Output