做英文网站用什么源码,自学家装设计从哪入手,网站建设业务员怎么做,软文标题例子功能#xff1a;ArrayList去除集合中字符串的重复值(字符串的内容相同)#xff0c;思路#xff1a;创建新集合方式。
第一种编译运行没问题#xff0c;第二种写法出错#xff0c;原因是不可以两次使用it.next()。
错误提示#xff1a;Exception in thread mainArrayList去除集合中字符串的重复值(字符串的内容相同)思路创建新集合方式。
第一种编译运行没问题第二种写法出错原因是不可以两次使用it.next()。
错误提示Exception in thread main java.util.NoSuchElementException public static ArrayList noRepeat2(ArrayList list){ArrayList newlist new ArrayList();Iterator it list.iterator();while(it.hasNext()){Object obj it.next();if(!newlist.contains(obj)){newlist.add(obj);}}return newlist;} public static ArrayList noRepeat2(ArrayList list){ArrayList newlist new ArrayList();Iterator it list.iterator();while(it.hasNext()){if(!newlist.contains(it.next())){newlist.add(it.next());}}return newlist;}