This code creates an ArrayList of String type named list_col and adds 7 elements to it. It then prints the ArrayList before and after reversing it using the Collections.reverse() method. Here is how the code works:
import java.util.*; public class Reverse_ArrayList { public static void main(String[] args) { List<String> list_col = new ArrayList<String>(); list_col.add("Black"); list_col.add("Orange"); list_col.add("Pink"); list_col.add("Blue"); list_col.add("White"); list_col.add("Yellow"); list_col.add("Purple"); System.out.println("Before Reversing :" + list_col); Collections.reverse(list_col); System.out.println("After Reversing :" + list_col); } }
Before Reversing :[Black, Orange, Pink, Blue, White, Yellow, Purple] After Reversing :[Purple, Yellow, White, Blue, Pink, Orange, Black]
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions