Home > Java > javaTutorial > body text

How to use forEach in java

王林
Release: 2023-04-18 16:16:05
forward
988 people have browsed it

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));
    }
  }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template