日期:2014-05-19 浏览次数:20731 次
import java.util.ArrayList;
import java.util.List;
public class Test4{
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
if (i==0) {
list.add("abc");
}else{
list.add("abc"+i);
}
}
boolean contain =new Test4().updateList(list);
System.out.println("contain="+contain);
List<String> list2 = new ArrayList<String>();
for (int i = 0; i < 12; i++) {
if (i<8 && i%2!=0) {
list2.add("age");
}else {
list2.add("字符串"+i);
}
}
list2 = updateString(list2);
for (int i = 0; i < list2.size(); i++) {
System.out.println(list2.get(i));
}
}
public boolean updateList(List<String> list){
boolean contain = false;
if (list.contains("abc")) {
contain = true;
}
return contain;
}
public static List<String> updateString(List<String> list){
System.out.println(list.size());
for (int i = 0; i < list.size(); i++) {
if (i%2!=0) {
if ("age".equals(list.get(i))) {
list.set(i, "年龄");
}
}
}
return list;
}
}