-3

我有一个来自循环语句的字符串列表,我不知道如何使其成为 ArrayList 然后单独调用字符串。这是while语句:

try {
    toDate=format.parse(str4);
    java.util.Date newValue= new SimpleDateFormat(OLD_FORMAT).parse(str4);
    String newValue2 = new SimpleDateFormat(NEW_FORMAT).format(newValue);
    // System.out.println(newValue2);
} catch (ParseException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}


//change the format of toDate 
try {
    newDateString=format.parse(str5);
    java.util.Date newqwe = new SimpleDateFormat(OLD_FORMAT).parse(str5);
    String newqwe2=new SimpleDateFormat (NEW_FORMAT).format(newqwe);
    //System.out.println(newqwe2);
} catch (ParseException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

//get the days between two dates then print it 
Calendar cal2 = Calendar.getInstance();
cal2.setTime(toDate);
while (cal2.getTime().before(newDateString)) {
    cal2.add(Calendar.DATE, 1);
    String datelist=(format.format(cal2.getTime()));

str4 来自与 str5 相同日期的标签,当单击按钮时,循环语句中的字符串将如下所示:

2013-05-03
2013-05-04
2013-05-05
2013-05-05
2013-05-06
2013-05-07
2013-05-08
2013-05-09
2013-05-10
2013-05-11
2013-05-12
2013-05-13
2013-05-14
2013-05-15
2013-05-16
2013-05-17
4

1 回答 1

2
List<String> list = new ArrayList<String>();

 list.add("2013-05-03");
 list.add("2013-05-04");
 ........etc

 for(String str:list)
  System.out.prinltn(str); // prints all the strings in list


System.out.println(list.get(index)); // prints string at specified index
于 2013-05-31T05:04:24.623 回答