随笔分类 - Java学习之集合进阶
摘要:由于Set集合是不存储重复元素的,所以在做此案例时,如果我正常添加一个重复元素是什么结果呢? public class HashSetDemo { public static void main(String[] args) { //创建HashSet集合对象 HashSet<Student> ha
阅读全文
摘要:由于LinkedList底层数据结构是链表,因此有一些特有的功能从链表对应到集合中。 框架代码: public class LinkedListDemo { public static void main(String[] args) { //创建集合对象 LinkedList<String> li
阅读全文
摘要:使用ArrayList存储字符串并遍历 public class ListDemo { public static void main(String[] args) { //创建ArrayList集合对象 ArrayList<String> arrayList = new ArrayList<Str
阅读全文
摘要:public class ListDemo { public static void main(String[] args) { //创建List集合对象 List<Student> list = new ArrayList<Student>(); //创建学生对象 Student s1 = new
阅读全文
摘要:public class ListDemo { public static void main(String[] args) { //示例1: int[] arr = {1,2,3,4,5}; for (int i : arr){ System.out.println(i); } System.ou
阅读全文
摘要:案例需求: 一个集合,里面有三个元素:list.add("hello"); list.add("world"); list.add("java"); 遍历集合,如果有”world“这个元素,我们就添加一个”javaee“元素进去。 代码如下: public class list_03 { publi
阅读全文
摘要:public class ListDemo { public static void main(String[] args) { //创建List集合对象 List<Student> list = new ArrayList<Student>(); //创建学生对象 Student s1 = new
阅读全文
摘要:集合元素框架 public class ListDemo02 { public static void main(String[] args) { //创建集合对象 List<String> list = new ArrayList<String>(); //添加元素 list.add("hello
阅读全文
摘要:public class CollectionDemo { public static void main(String[] args) { //创建collection集合对象 Collection<Student> c = new ArrayList<Student>(); //创建学生对象 S
阅读全文
摘要:Iterator : 迭代器,集合的专用遍历方式Iterator <E> iterator() : 返回此集合中元素的迭代器,通过集合的iterator()方法得到迭代器是通过集合的iterator()方法得到的,所以我们说它是依赖于集合而存在的Iterator中的常用方法 E next() : 返
阅读全文
摘要:boolean add(E e) import java.util.ArrayList; import java.util.Collection; public class CollectionDemo_02 { public static void main(String[] args) { //
阅读全文