Create a gist now

Instantly share code, notes, and snippets.

ArrayListの勉強
import java.util.*;
class Date{
int x;
int y;
int z;
Date(int x, int y, int z){
this.x = x;
this.y = y;
this.z = z;
}
void PrintDate(int i){
System.out.println("date" + (i+1) + " : " + x + ", " + y + ", " + z);
}
}
public class ArrayListEx1{
public static void main(String[] args) {
// ジェネリクス
ArrayList<Date> date = new ArrayList<Date>();
date.add(new Date(2016, 12, 20));
date.add(new Date(2017, 1, 1));
date.add(new Date(2017, 2, 2));
for(int i = 0; i < date.size(); i++){
Date d1 = date.get(i); // 要素取り出し
d1.PrintDate(i);
}
Date d = date.remove(1); // 削除
System.out.println("------------------------");
for(int i = 0; i < date.size(); i++){
Date d2 = date.get(i); // 要素取り出し
d2.PrintDate(i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment