178. List<String> list = new ArrayList<>(1);
list.add(“hoge”);
Set<String> set = new HashSet<>(1);
set.add(“hoge”);
Map<String, String> map = new HashMap<>(1);
map.add(“hoge”, “hoge”);
Selfish Implement VS Collections
212. Date,Calendar VS Date and Time
// 一ヶ月後の日付取得
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.MONTH, 1);
// yyyy-MM を出力
System.out.println(cal.get(Calendar.YEAR) +
“-” + (cal.get(Calendar.MONTH) + 1));
213. // 一ヶ月後の日付取得
YearMonth nowYearMonth = YearMonth.now();
YearMonth nextYearMonth = nowYearMonth.plus(1,
ChronoUnit.MONTHS);
// yyyy-MM を出力
System.out.println(nextYearMonth.getYear() + “-” +
nextYearMonth.getMonthValue());
Date,Calendar VS Date and Time
214. // 一ヶ月後の日付取得
YearMonth nowYearMonth = YearMonth.now();
YearMonth nextYearMonth = nowYearMonth.plus(1,
ChronoUnit.MONTHS);
// yyyy-MM を出力
System.out.println(nextYearMonth.getYear() + “-” +
nextYearMonth.getMonthValue());
Date,Calendar VS Date and Time
System.out.println(nextYearMonth);
で良いんだけどね
215. Date,Calendar VS Date and Time
// 文字列からDateを作る
SimpleDateFormat sdf = new SimpleDateFormat();
sdf.applyPattern(“yyyy/MM/dd”);
Date date = sdf.parse(“2015/11/28”);
216. // 文字列からDateを作る
DateTimeFormatter formatter = DateTimeFormatter.
ofPattern(“yyyy/MM/dd”);
LocalDate date = LocalDate.parse(“2015/11/28”,
formatter);
※といってもjava.util.DateとLocalDateは全く別もの。。。
Date,Calendar VS Date and Time