Java by API/java.util/Queue

Материал из Java эксперт
Версия от 14:10, 31 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Queue: add(String e)

  
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.add("Hello");
    queue.add("World");
    List<String> list = new ArrayList<String>(queue);
    System.out.println(list);
  }
}





Queue: element()

 
import java.util.LinkedList;
import java.util.Queue;
public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.offer("First");
    queue.offer("Second");
    queue.offer("Third");
    queue.offer("Fourth");
    System.out.println("Size: " + queue.size());
    System.out.println("Queue head using peek   : " + queue.peek());
    System.out.println("Queue head using element: " + queue.element());
    Object data;
    while ((data = queue.poll()) != null) {
      System.out.println(data);
    }
  }
}





Queue: peek()

 
import java.util.LinkedList;
import java.util.Queue;
public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.offer("First");
    queue.offer("Second");
    queue.offer("Third");
    queue.offer("Fourth");
    System.out.println("Size: " + queue.size());
    System.out.println("Queue head using peek   : " + queue.peek());
    System.out.println("Queue head using element: " + queue.element());
    Object data;
    while ((data = queue.poll()) != null) {
      System.out.println(data);
    }
  }
}





Queue: poll()

 
import java.util.LinkedList;
import java.util.Queue;
public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.offer("First");
    queue.offer("Second");
    queue.offer("Third");
    queue.offer("Fourth");
    System.out.println("Size: " + queue.size());
    System.out.println("Queue head using peek   : " + queue.peek());
    System.out.println("Queue head using element: " + queue.element());
    Object data;
    while ((data = queue.poll()) != null) {
      System.out.println(data);
    }
  }
}





Queue: size()

 
import java.util.LinkedList;
import java.util.Queue;
public class Main {
  public static void main(String[] args) {
    Queue<String> queue = new LinkedList<String>();
    queue.offer("First");
    queue.offer("Second");
    queue.offer("Third");
    queue.offer("Fourth");
    System.out.println("Size: " + queue.size());
    System.out.println("Queue head using peek   : " + queue.peek());
    System.out.println("Queue head using element: " + queue.element());
    Object data;
    while ((data = queue.poll()) != null) {
      System.out.println(data);
    }
  }
}