(JAVA)集合Collection3

package cn.cast.collection;/*** @author zhangyu* @date 2021年08月28日 4:12 下午* 使用集合存储自定义对象,并迭代* 在迭代器中,next()在运行中,不能添加对象,且不能多次使用*/
import cn.book.objectarr.Student;import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;public class CollectionDemo3 {public static void main(String[] args) {Collection col = new ArrayList();col.add(new Student("a",19));col.add(new Student("b",12));col.add(new Student("c",20));col.add(new Student("d",25));col.add(new Student("e",90));Iterator it = col.iterator();while (it.hasNext()){System.out.println(((Student)it.next()).getName()+((Student)it.next()).getName());}}
}

指针异常

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421776.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【零基础学习iOS开发】【02-C语言】05-进制

上一讲简单介绍了常量和变量,这讲补充一点计算机的基础知识---进制。 我们先来看看平时是如何表示一个整数的,最常见的肯定是用阿拉伯数字表示,比如“十二”,我们可以用12来表示,其实这种表示方式是基于一种叫做“十进…

(JAVA)hashcode

package cn.cast.collection;/*** author Alina* date 2021年09月19日 8:00 下午* 对象的哈希值* 1.JAVA中,每一个类,都有一个十进制数的哈希值* 2.十进制数,叫做这个对象的哈希值* 3.class Object(){* public native int hashCode();* …

(JAVA)红黑树之自然顺序排序和自定义排序方式

package cn.book.objectarr;/*** author alina* date 2021年08月22日 6:57 下午*/ public class Student implements Comparable<Student> {private String name;private int age;public Student(){}/***** author Alina* date 2021/9/21 9:41 下午* param o* return int…

php正则表达式如何找到匹配模式中的最后一组

转载于:https://www.cnblogs.com/MyFlora/archive/2013/06/07/3124073.html

苏教版国标本小学语文第一册汉字笔画

苏教版国标本小学语文第一册汉字笔画 转载于:https://www.cnblogs.com/shangdawei/archive/2013/06/09/3129240.html