私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第8章 集合操作

第八章集合操作 急 1.对数组对象的操作(Arrays), 2.对象集合(Set) 3.对象列表(儿ist) 4.对象映射(Map) 5.对对象数组的操作(Collections) 6.枚举(Enumeration)和送代(Iterator) 7.小结
1 1. 对数组对象的操作(Arrays) 2. 对象集合(Set) 3. 对象列表(List) 4. 对象映射(Map) 5. 对对象数组的操作(Collections) 6. 枚举(Enumeration)和迭代(Iterator) 7. 小结 第八章 集合操作

对数组对象的操作(Arrays) 急 ■java.util.Arrays This class contains various methods for manipulating arrays ■排序(sorting). ■ 搜索(searching) ■ 填充(filling) 2
2 ◼ java.util.Arrays类 ◼ This class contains various methods for manipulating arrays ◼ 排序(sorting) ◼ 搜索(searching) ◼ 填充(filling) 对数组对象的操作(Arrays)

boolean[],char[],byte[],short[],int[],long[],double[],float[] Object[] 全部是静态方法 ■ public static int binarySearch(byte[]a,byte key) Searches the specified array of bytes for the specified value using the binary search algorithm. public static boolean equals(byte[]a,byte[]a2) Returns true if the two specified arrays of bytes are equal to one another. ◆ public static void fill(byte[]a,byte val) Assigns the specified byte value to each element of the specified array of bytes. public static void fill(byte[]a,int fromIndex,int toIndex, byte val) Assigns the specified byte value to each element of the specified range of the specified array of bytes. public static void sort(byte[]a) Sorts the specified array of bytes into ascending numerical order. 3
3 ◼ 全部是静态方法 ◼ public static int binarySearch(byte[] a, byte key) Searches the specified array of bytes for the specified value using the binary search algorithm. ◼ public static boolean equals(byte[] a, byte[] a2) Returns true if the two specified arrays of bytes are equal to one another. ◼ public static void fill(byte[] a, byte val) Assigns the specified byte value to each element of the specified array of bytes. ◼ public static void fill(byte[] a, int fromIndex, int toIndex, byte val) Assigns the specified byte value to each element of the specified range of the specified array of bytes. ◼ public static void sort(byte[] a) Sorts the specified array of bytes into ascending numerical order. 对数组对象的操作(Arrays) boolean[], char[], byte[], short[], int[], long[], double[], float[] Object[]

对教组对象的操作(Arrays) import java.util.Arrays; public class ArrayDemo1 public static void main(String args[]) int[]a1 new int[10] int[]a2 new int[10]; Arrays.fill(a1,47); Arrays.fill(a2,47); System.out.printIn(Arrays.equals(a1,a2); a2[3]=11;a2[2]=9; System.out.println(Arrays.equals(a1,a2)); Arrays.sort(a2); System.out.println(Arrays.binarySearch(a2,11)); 4
4 对数组对象的操作(Arrays) import java.util.Arrays; public class ArrayDemo1 { public static void main(String args[]) { int[] a1 = new int[10]; int[] a2 = new int[10]; Arrays.fill(a1, 47); Arrays.fill(a2, 47); System.out.println(Arrays.equals(a1, a2)); a2[3]=11; a2[2]=9; System.out.println(Arrays.equals(a1, a2)); Arrays.sort(a2); System.out.println(Arrays.binarySearch(a2, 11)); } }

第八章集合操作 急 1.对数组对象的操作(Arrays). 2.对象集合(Set) 3.对象到表(List) 4.对象映射(Map) 5.对对象数组的操作(Collections) 6.枚举(Enumeration)和送代(Iterator) 7.小结
5 1. 对数组对象的操作(Arrays) 2. 对象集合(Set) 3. 对象列表(List) 4. 对象映射(Map) 5. 对对象数组的操作(Collections) 6. 枚举(Enumeration)和迭代(Iterator) 7. 小结 第八章 集合操作

对象集合(Set) 盖 ■数学上“集合”瓶念的抽象,无序 A Set is a collection that cannot contain duplicate elements. ■ 集合与元素 集合之间 ■ 无序集合和有序集合 6
6 ◼ 数学上“集合”概念的抽象,无序 ◼ A Set is a collection that cannot contain duplicate elements. ◼ 集合与元素 ◼ 集合之间 ◼ 无序集合和有序集合 对象集合(Set)

对象集合(Set) 急 java.util.Set接口(集合与元素) public boolean add(Object o) Adds the specified element to this set if it is not already present. ■ public boolean remove(Object o) Removes the specified element from this set if it is present. public boolean contains(Object o) Returns true if this set contains the specified element. ■ public int size( Returns the number of elements in this set. 7
7 ◼ java.util.Set 接口 (集合与元素) ◼ public boolean add(Object o) Adds the specified element to this set if it is not already present. ◼ public boolean remove(Object o) Removes the specified element from this set if it is present. ◼ public boolean contains(Object o) Returns true if this set contains the specified element. ◼ public int size() Returns the number of elements in this set. 对象集合(Set)

D:\java FindDups1 i came i saw i left 对象集合(Set Duplicate:i Duplicate:i java.util.Hash$4 distinct words:[came,left,saw,il ■无序集合 D import java.util.*; public class SetDemo1 public static void main(String args[]){ Set s new HashSet(); for (int i=0;i<args.length;i++) if (!s.add(args[i])) System.out.println("Duplicate:"+args[i]); System.out.println(s.size()+"distinct words:"+s); 8
8 ◼ java.util.HashSet implement java.util.Set ◼ 无序集合 对象集合(Set) import java.util.*; public class SetDemo1 { public static void main(String args[]) { Set s = new HashSet(); for (int i=0; i<args.length; i++) if (!s.add(args[i])) System.out.println("Duplicate: "+args[i]); System.out.println(s.size()+" distinct words: "+s); } } D:\java FindDups1 i came i saw i left Duplicate: i Duplicate: i 4 distinct words: [came, left, saw, i] D:\

对象集合(Set) 急 java.util.Set接口(集合之间) ■ public boolean containsAll(Collection c) Returns true if this set contains all of the elements of the specified collection. public boolean addAll(Collection c) Adds all of the elements in the specified collection to this set if they're not already present. ■ public boolean removeAll(Collection c) Removes from this set all of its elements that are contained in the specified collection. public boolean retainAll(Collection c) Retains only the elements in this set that are contained in the specified collection. 9
9 ◼ java.util.Set接口 (集合之间) ◼ public boolean containsAll(Collection c) Returns true if this set contains all of the elements of the specified collection. ◼ public boolean addAll(Collection c) Adds all of the elements in the specified collection to this set if they're not already present. ◼ public boolean removeAll(Collection c) Removes from this set all of its elements that are contained in the specified collection. ◼ public boolean retainAll(Collection c) Retains only the elements in this set that are contained in the specified collection. 对象集合(Set)

D:\java FindDups2 i came i saw i left 对象集合(Set i Unique words:[came,left,saw] Duplicate words:[i] java.util.Hashs import java.util.*; D public class SetDemo2 public static void main(String args[]){ Set uniques new HashSet(); Set dups new HashSet(); for (int i=0;i<args.length;i++) if (!uniques.add(args[i])) dups.add(args[i]); uniques.removeAll(dups); System.out.println("Unique words:"uniques); System.out.printin("Duplicate words:"dups); 10
10 ◼ java.util.HashSet implement java.util.Set 对象集合(Set) import java.util.*; public class SetDemo2 { public static void main(String args[]) { Set uniques = new HashSet(); Set dups = new HashSet(); for (int i=0; i<args.length; i++) if (!uniques.add(args[i])) dups.add(args[i]); uniques.removeAll(dups); System.out.println("Unique words: " + uniques); System.out.println("Duplicate words: " + dups); } } D:\java FindDups2 i came i saw i left Unique words: [came, left, saw] Duplicate words: [i] D:\
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第1章 Java概述(负责人:尹菡).ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》笔试卷B(答案).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》笔试卷B(试题).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》笔试卷A(答案).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》笔试卷A(试题).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》机考卷B(答案).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》机考卷B(试题).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》机考卷A(答案).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《Java程序设计》机考卷A(试题).doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)java上机题及答案3.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)java上机题及答案2.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)java上机题及答案1.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)java练习题及答案3.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)java练习题及答案2.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)java练习题及答案1.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《JAVA》试题6及答案.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《JAVA》试题5及答案.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《JAVA》试题4及答案.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《JAVA》试题3及答案.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程教学资源(试卷习题)《JAVA》试题2及答案.doc
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第10章 数据库编程.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第11章 Swing组件.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第2章 Java基础.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第3章 面向对象的程序设计概念.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第4章 类的继承和多态.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第5章 接口和包.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第6章 异常.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第7章 常用实用类.ppt
- 私立华联学院:《跨平台开发语言(JAVA)》课程电子教案(PPT教学课件)第9章 输入与输出.ppt
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)实训指导书(主讲:崔英敏).pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第一章 Linux的启源与发展历史(主讲:崔英敏).pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第二章 Linux的基础应用.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第三章 VIM文件编辑器.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第四章 Linux用户组及权限管理.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第五章 Linux文件系统.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第六章 Linux系统与网络管理.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第七章 定制SHELL环境.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第九章 进程管理与内核服务.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第八章 SHELL编程基础.pdf
- 私立华联学院:《Linux系统管理》课程教学资源(课件讲稿,打印版)第十章 软件包管理与定制系统.pdf