Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package coda;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.LinkedList;
  5. import java.util.List;
  6.  
  7. public class main {
  8. public static void main(String[] args) {
  9. List<Integer> list1=new ArrayList<>();
  10. Coda<Integer> coda1=new Coda<>(list1);
  11. System.out.println("LISTA INTEGER");
  12. System.out.println("lista vuota? "+coda1.isEmpty());
  13. coda1.put(11);
  14. coda1.put(22);
  15. coda1.put(33);
  16. coda1.put(44);
  17. System.out.println("lista vuota? "+coda1.isEmpty());
  18. System.out.println("tolgo dalla coda: "+coda1.get());
  19.  
  20. List<Double> list2=new LinkedList<>();
  21. Coda<Double> coda2=new Coda<>(list2);
  22. System.out.println("LISTA DOUBLE");
  23. System.out.println("lista vuota? "+coda2.isEmpty());
  24. coda2.put(100.99);
  25. coda2.put((double) 220);
  26. coda2.put((double) 330);
  27. coda2.put((double) 440);
  28. System.out.println("lista vuota? "+coda2.isEmpty());
  29. System.out.println("tolgo dalla coda: "+coda2.get());
  30. }
  31.  
  32. public static class Coda<T> {
  33.  
  34. List<T> list;
  35.  
  36. public Coda(List<T> list) {
  37. this.list = list;
  38. }
  39.  
  40. public boolean isEmpty(){
  41. return list.isEmpty();
  42. }
  43.  
  44. public T get(){
  45. return list.remove(0);
  46. }
  47.  
  48. public void put(T element){
  49. list.add(element);
  50. }
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement