【发布时间】:2017-05-21 07:57:49
【问题描述】:
我目前正在尝试编写日历。我将约会保存在另一个 ArrayList 中的 2 个不同的 ArrayList 中。
字符串(主题、地点、人物)进入另一个 ArrayList = arStr
中的第一个 ArrayList
整数(日期和时间)进入另一个 ArrayList = arInt 中的第二个 ArrayList
当我创建约会时,我想根据日期对其进行排序。因此,如果我想添加一个新约会,它应该保存在外部列表中已保存的约会之上或之下(取决于时间)。如果他们的日期晚于新的,则已经保存的应该在外部列表中。完成后,我想将 String Appointment 连接到 Int Appointment。
我的问题是我找不到以这种方式对它们进行排序的方法,谁能帮助我:)?
public class Calender
{
public static ArrayList<ArrayList<Integer>> arInt = new ArrayList<ArrayList<Integer>>();
public static ArrayList<ArrayList<String>> arStr = new ArrayList<ArrayList<String>>();
public static Scanner read = new Scanner(System.in);
public static int counter = 0; // counts all made appointments
public static void main (String[]args)
{
//Adding Arrylists for space
arInt.add(new ArrayList());
arStr.add(new ArrayList());
arInt.add(new ArrayList());
arStr.add(new ArrayList());
// This is one Appointment ( Subject, Year, Month, Day, Hour )
// Already saved Appointment
counter++;
arStr.get(0).add("3.Liste");
arInt.get(0).add(2017);
arInt.get(0).add(2);
arInt.get(0).add(8);
arInt.get(0).add(16);
// new Appointment
counter++;
String betreff = "1. Appointment";
int year = 2017;
int month = 2;
int day = 8;
int hours = 15;
// How to compare these Variables with the first Appointment and save it accordigly ?
}
}
【问题讨论】: