- 1、本文档共27页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
数组和集合类
Arrays An array is a structure that holds a multiple values of the same type. An array is a fixed-length structure. Each item in an array is called an element, and each element is accessed by its numerical index. Declaring a Variable to Refer to an Array type[] arrayName; type is the data type of the contained elements [] brackets are special symbols indicating that this variable holds an array Note: the declaration does not actually create an array Examples byte[] anArrayOfBytes; long[] anArrayOfLongs; float[] anArrayOfFloats; double[] anArrayOfDoubles; boolean[] anArrayOfBooleans; char[] anArrayOfChars; String[] anArrayOfStrings; Double[] anArrayOfDoubles; Creating an Array One way to create an array is with the new operator. new type[arraySize] Exercise 1 int[] intArray = new int[5]; double[] doubleArray = new double[5]; intArray[1]和doubleArray[1]有值吗?如果有,值分别是多少? Exercise 2 String[] sArray = new String[5]; sArray[0]的值是多少? sArray[0].length()的值是多少? Initializing an Array int[] anArray = {100, 200, 300, 400, 500, 600, 700, 800, 900, 1000}; boolean[] answers = {true,false,true,true,ture}; Accessing an Array Element int[] anArray = new int[10]; anArray[0] = 100; anArray[1] = 200; anArray[2] = 300; System.out.println(anArray[0]); Exercise 3 boolean[] answers ={true,false,true}; 编写一段代码,用循环遍历输出answers中的元素 数组的缺陷 定长:在事先不知道有多少元素的情况下不太适用。 存储同类型的数据 Collection Framework java.util包中定义了各种用于集合操作的类和接口,这些类和接口构成了Java语言的集合框架(Collection Framework) Java集合中不能存放基础数据类型 Collection Framework 根据不同类型的集合的特点和用途,集合框架在设计的时候将集合分为以下三种类型: (1) 集合(Set) — 无重复对象 (2) 列表(List) — 允许重复对象,按index排序,可按index检索,类似数组 (3) 映射(Map) — 每个元素由key对象和value对象组成,key不重复(有些情况下按key排序,value可重复) List接口 存放对象,对象可重复,按index排序,可按index检索,类似数组。 ArrayList list = new ArrayList(); list.add(黑桃A); list.add(红桃A); list.add(黑桃A); list.add(1,new Double(23.3)); for(int i=0;ilist.size();i++){ System.out.println(list.get(i)); } 使用Iterator遍历List Iterator it = list.iterator(); while(it.
您可能关注的文档
- 教二08工硕考前(词).ppt
- 教师招聘笔试备考――音乐乐理知识(一).doc
- 教师招聘笔试备考――音乐乐理知识(二).doc
- 教材有,课标无.doc
- 教案学案一体化讲义.doc
- 教育学课程案例.ppt
- 数处仿真作业.doc
- 数字信号处理_Lecture 3.ppt
- 数字信号处理_第4章IIR数字滤波器的3.ppt
- 数字信号处理——Chapt5.ppt
- 2025年延边市应急管理系统事业单位人员招聘笔试备考试题及答案解析.docx
- 2025年山南市血液中心事业单位人员招聘笔试备考试题及答案解析.docx
- 2025年鄂州市政务服务中心(综合窗口)人员招聘笔试备考试题及答案解析.docx
- 天然气管道焊接施工方案.pptx
- 2025年呼伦贝尔市劳动保障监查系统事业单位人员招聘笔试备考试题及答案解析.docx
- 2025年铜仁市劳动保障监查系统事业单位人员招聘笔试备考试题及答案解析.docx
- 2025年吴忠市政务服务中心(综合窗口)人员招聘笔试备考试题及答案解析.docx
- 2025年张掖市政务服务中心(综合窗口)人员招聘笔试备考试题及答案解析.docx
- 2025年咸阳市市场监督管理系统事业单位人员招聘笔试备考试题及答案解析.docx
- 2025年兴安市市场监督管理系统事业单位人员招聘笔试备考试题及答案解析.docx
文档评论(0)