//向list集合添加姓名{张三,李四,王五,二丫,钱六,孙七},将二丫替换为王小丫,写入到"D:\\stuinfo.txt"
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Test05{
public static void main(String[] args) throws IOException{
List list = new ArrayList();
list.add("张三");
list.add("李四");
list.add("王五");
list.add("二丫");
list.add("钱六");
list.add("孙七");
for(int i=0;i<list.size();i++){
if("二丫".equals(list.get(i))){
list.set(i,"王小丫");
}
}
BufferedWriter bw=new BufferedWriter(new FileWriter("stuinfo.txt"));
bw.write((list).toString());
bw.close();
}
}
代码运行没错,可是有好多的黄线,求答
|
|