fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String[] myArray = {"Turma A", "Turma B", "Turma C"};
  14. List<String> arrayList = new ArrayList<String> (Arrays.asList(myArray));
  15.  
  16. DateFormat df = new SimpleDateFormat ("dd/MM/yyyy");
  17. Date dt1 = df.parse ("01/10/2016"); // Data inicial
  18. Date dt2 = df.parse ("10/10/2016"); //
  19. Calendar cal1 = Calendar.getInstance();
  20. cal1.setTime (dt1);
  21. Calendar cal2 = Calendar.getInstance();
  22. cal2.setTime (dt2);
  23. cal2.add(Calendar.DATE,1);
  24. //cria o iterator sob o arraylist
  25. Iterator<String> it = arrayList.iterator();
  26.  
  27. for (Calendar cal = cal1; cal.compareTo (cal2) <= 0; cal.add (Calendar.DATE, 1)) {
  28. //checa se o iterator já chegou ao fimm
  29. //se sim, o reinicia
  30. if(!it.hasNext()){
  31. it = arrayList.iterator();
  32. }
  33. // next() exibe o item seguinte do arraylist
  34. System.out.println (df.format (cal.getTime()) +" " + it.next());
  35. }
  36. }
  37. }
Success #stdin #stdout 0.06s 711680KB
stdin
Standard input is empty
stdout
01/10/2016 Turma A
02/10/2016 Turma B
03/10/2016 Turma C
04/10/2016 Turma A
05/10/2016 Turma B
06/10/2016 Turma C
07/10/2016 Turma A
08/10/2016 Turma B
09/10/2016 Turma C
10/10/2016 Turma A
11/10/2016 Turma B