Home  >  Article  >  Java  >  How to use forEach in java

How to use forEach in java

王林
王林forward
2023-04-18 16:16:05990browse

Code:

import java.util.*;
import java.text.*;

class Test {
  public static void main(String args[]) throws Exception{
    String a[] = {"~`!@#","$%^&*","()-_+","=|{}","[]:;"","',.?/"};
    for(String s:a) {
      System.out.println(s);
    }

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Calendar cal = Calendar.getInstance();

    Date date0 = formatter.parse("2008-02-29 23:58:58");
    cal.setTime(date0);

    cal.add(Calendar.MINUTE, 5);
    Date date1 = cal.getTime();

    cal.add(Calendar.MONTH, 1);
    Date date2 = cal.getTime();
    
    Listlist0 = new ArrayList();
    
    list0.add(date0);
    list0.add(date1);
    list0.add(date2);
    
    for(Date d:list0){
      System.out.println(formatter.format(d));
    }
  }
}

The above is the detailed content of How to use forEach in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete