ArrayList的addAll方法使用注意
来源:互联网 发布:淘宝宽屏 编辑:程序博客网 时间:2024/05/18 04:57
<span style="font-size:18px;">package com.robot.test;import java.util.ArrayList;public class TestCode {public static void main(String[] args) {ArrayList<Student> stuList = new ArrayList<Student>();Student s1 = new Student(12, "jack");Student s2 = new Student(23, "Ann");Student s3 = new Student(76, "Mike");stuList.add(s1);stuList.add(s2);stuList.add(s3);ArrayList<Student> stuList2 = new ArrayList<Student>();stuList.addAll(stuList2); // 正确ArrayList<Student> stuList3 = null;stuList.addAll(stuList3); // 报错,由于stuList3为null指针}}</span>
<span style="font-size:18px;">package com.robot.test;public class Student{<span style="white-space:pre"></span>public int age;<span style="white-space:pre"></span>public String name;<span style="white-space:pre"></span>Student(int age, String name) {<span style="white-space:pre"></span>this.age = age;<span style="white-space:pre"></span>this.name = name;<span style="white-space:pre"></span>}}</span>
总结:在使用ArrayList的addAll()方法的时候一定要进行非null的判断。
0 0
- ArrayList的addAll方法使用注意
- Java arrayList addAll方法使用
- Arraylist.addall(c) 方法
- java Arraylist.addAll方法---arraycopy
- ArrayList中toArray()方法的使用注意
- Java Collections.addAll() 与 ArrayList.addAll() 的区别
- Java Collections.addAll() 与 ArrayList.addAll() 的区别
- ArrayList的addAll 与 for循环比较
- 关于arrayList的add和addall
- 关于arrayList的add和addall
- java list.addAll方法的一些使用记录
- 关于list的addAll方法
- ArrayList类中的subList方法使用注意
- ArrayList.addAll(Collection<? extends E> c) 方法讲解
- ArrayList addAll and ArrayCopy
- ArrayList中去重方法及注意的细节
- ArrayList类的ToArray()使用注意点
- List的【addAll(List list)】方法
- 操作符重载
- jquery 中的empty()和remove()
- 把工作都放在文档里,解放思想。
- 在恰当的地方使用MongoDB的WriteConcern.SAFE参数
- UIGestureRecognizer学习笔记
- ArrayList的addAll方法使用注意
- HYSBZ - 1026 windy数 数位DP
- C#常用编程技巧(待续)
- Codeforces Round #279 (Div. 2) C. Hacking Cypher
- 统计字母‘A’出现的次数
- Codeforces Team Olympiad(暴力)
- Swift学习笔记一
- escape()、encodeURI()、encodeURIComponent()区别详解
- 游戏种通用提示框的设计模板和应用(待续)