代码:
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)); } } }
以上是java中的forEach怎么用的详细内容。更多信息请关注PHP中文网其他相关文章!