/**
* 13.给定一个list集合:{"张柏芝","刘德华","张亮","张靓颖","杨颖","黄晓明"}
* 编写一个方法:将list集合中所有姓张并且姓名长度为3个字符的姓名,写入到D:\\a.txt中
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
ArrayList<String> list = new ArrayList<String>();
list.add("张柏芝");
list.add("刘德华");
list.add("张亮");
list.add("张靓颖");
list.add("杨幂");
list.add("黄晓明");
BufferedWriter fw = new BufferedWriter(new FileWriter("a.txt"));
String s1 = list.get(0).toString(); //这里是先拿第一个元素写的,还没写完
if ("张".equals(s1.indexOf(0)) && s1.length() == 3) {
System.out.println(s1); //但是一进到if语句里面就连打印都打印不出来了,不知道什么原因?
fw.write(s1);
}
fw.close();
}
|
|