Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.ConcurrentLinkedQueue; public class ConcurrentLinkedQueueToArrayExample2 { public static void main(String[] args) { ConcurrentLinkedQueue
queue = new ConcurrentLinkedQueue(); queue.add(8); queue.add(5); queue.add(17); queue.add(80); queue.add(2); Object[] a = queue.toArray(); System.out.print("Elements : "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } System.out.println(); System.out.print("Ascending order : "); for (int i = 0; i < a.length; i++) { for (int j = i + 1; j < a.length; j++) { Object temp = 0; if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } for (int i = 0; i < a.length; i++) { System.out.print(a[i] + " "); } } }
Output