prg0oops

Pasted Oct 9, 2026, 8:45 AM1 file67 lines

Scan to open on your phone

Point a camera at the QR code - it opens this exact paste, no app needed.

https://codepastes.com/zzgt0f8kax971zzg
untitled
package saumil1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;

public class lab9 {
	public static void main(String[] args) 
	{
		System.out.println("---ArrayList Operations---");
		ArrayList<String>arrayList=new ArrayList<>();
		arrayList.add("Apple");
		arrayList.add("Banana");
		arrayList.add("Mango");
		arrayList.add("Grapes");
		System.out.println("initial ArrayList:"+arrayList);
		arrayList.add(1,"Orange");
		System.out.println("After insert at index 1:"+arrayList);
		arrayList.remove("Banana");
		System.out.println("After removing Banana:"+arrayList);
		Collections.sort(arrayList);
		System.out.println("After sorting:"+arrayList);
		System.out.println("Element at index 2:"+arrayList.get(2));
		System.out.println("Size of ArrayList:"+arrayList.size());
		System.out.println("Contains 'Mango'?"+arrayList.contains("Mango"));
		
		System.out.println("---LinkedList Operations---");
		LinkedList<Integer>linkedList =new LinkedList<>();
		linkedList.add(10);
		linkedList.add(20);
		linkedList.add(30);
		linkedList.addFirst(5);
		linkedList.addLast(40);
		System.out.println("LinkedList:"+linkedList);
		linkedList.removeFirst();
		linkedList.removeLast();
		System.out.println("After removing first and last:"+linkedList);
		System.out.println("First element:"+linkedList.getFirst());
		System.out.println("Last element:"+linkedList.getLast());
		Iterator <Integer> it=linkedList.iterator();
			System.out.print("Iterating LinkedList:");
			while(it.hasNext())
			{
				System.out.print(it.next()+" ");
				
			}
			System.out.println();
			System.out.println("---HashSet Operations---");
			HashSet<String>hashSet=new HashSet<>();
			hashSet.add("Red");
			hashSet.add("Green");
			hashSet.add("Blue");
			hashSet.add("Red");
			System.out.println("HashSet (duplicates ignored):"+hashSet);
			System.out.println("Size of HashSet:"+hashSet.size());
			System.out.println("Iterating HashSet:");
			for(String color:hashSet)
			{
				System.out.println(color+" ");
			}
			System.out.println();
			
	}

}

2,111 chars · codepastes.com