implement a generic Queue class in java and work with different data types.
import java.util.LinkedList;
import java.util.Queue;
public class QueueTest {
	public static void main(String[] args) {
		Queue<String> queueOne = new LinkedList<>();
		queueOne.offer("New-York city");
		queueOne.offer("London");
		queueOne.offer("Chicogo");
		queueOne.offer("Liverpool");
		System.out.println(queueOne.peek());
		String town;
		while ((town = queueOne.poll()) != null) {
			System.out.println(town);
			Queue<Integer> queueTwo = new LinkedList<>();
			for (int i = 0; i < 5; i++)
				queueTwo.add(i);
			System.out.println("Elements of queue " + queueTwo);
			int removedele = queueTwo.remove();
			System.out.println("removed element-" + removedele);
			System.out.println(queueTwo);
			int head = queueTwo.peek();
			System.out.println("head of queue-" + head);
			int size = queueTwo.size();
			System.out.println("Size of queue-" + size);
		}
	}
}
Comments