上海交通大学:《操作系统 Operating System》课程教学资料(JAVA PPT)lec4

CS3101-3 Programming Language-Java Fall 2004 Oct.6
CS3101-3 Programming Language – Java Fall 2004 Oct. 6

Containers O Hold a group of objects o Significantly increase your programming power OAll perform bound checking ● array:efficient,can hold primitives Collection:a group of individual elements OList,Set o Map:a group of key-value object pairs OHashMap o Misleading:sometimes the whole container libraries are also called collection classes
Containers l Hold a group of objects l Significantly increase your programming power l All perform bound checking l array: efficient, can hold primitives l Collection: a group of individual elements ¡List, Set l Map: a group of key-value object pairs ¡HashMap l Misleading: sometimes the whole container libraries are also called collection classes

array o Most efficient way to do random access o Size is fixed and cannot be changed for the lifetime oIf run out of space,have to create a new one and copy everything Advantage:can hold primitives
array lMost efficient way to do random access lSize is fixed and cannot be changed for the lifetime lIf run out of space, have to create a new one and copy everything lAdvantage: can hold primitives

Other containers ●Can only take object ●Have to“wrap”primitives Oint->Integer,double->Double o Have to cast or unwrap on retrieval ● Slow,error prone,tedious.... Fixed by JDK1.5,hopefully oAdvantage:automatic expanding
Other containers lCan only take object lHave to “wrap” primitives ¡int -> Integer, double-> Double lHave to cast or unwrap on retrieval lSlow, error prone, tedious…. lFixed by JDK1.5, hopefully lAdvantage: automatic expanding

Arrays class ●In java.util,a "wrapper”class for array OA set of static utility methods Ofill():fill an array with a value Oequals():compare two arrays for equality Osort():sort an array ObinarySearch():find one element in a sorted array O All these methods overload for all primitive types and Object
Arrays class lIn java.util, a “wrapper” class for array lA set of static utility methods ¡fill(): fill an array with a value ¡equals(): compare two arrays for equality ¡sort(): sort an array ¡binarySearch(): find one element in a sorted array lAll these methods overload for all primitive types and Object

Arrays.sort() ●6 Sorts the objects into ascending order,according to their natural ordering o This sort is guaranteed to be stable:equal elements will not be reordered as a result of the sort oYou can specify a range.The range to be sorted extends from index fromlndex,inclusive,to index tolndex,exclusive. oThe objects need to comparable or there is a special comparator
Arrays.sort() l Sorts the objects into ascending order, according to their natural ordering l This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort l You can specify a range. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive. l The objects need to comparable or there is a special comparator

Arrays.sort()cont. sort(array),sort(array,fromlndex,tolndex) OAll elements in the array must implement the Comparable interface sort(array,comparator) sort(array,fromlndex,tolndex,comparator) oAll elements in the array must be mutually comparable by the specified comparator
Arrays.sort() cont. lsort(array), sort(array, fromIndex, toIndex) lAll elements in the array must implement the Comparable interface lsort(array, comparator) lsort(array, fromIndex, toIndex, comparator) lAll elements in the array must be mutually comparable by the specified comparator

Comparable interface oWith a single method compareTo() o Takes another Object as argument ●And returns: ONegative value if this is less than argument OZero value if this is equal to argument Opositive value if this is greater than argument
Comparable interface lWith a single method compareTo() lTakes another Object as argument lAnd returns: ¡Negative value if this is less than argument ¡Zero value if this is equal to argument ¡positive value if this is greater than argument

Comparator interface Two methods:compare(),equals() oOnly need to implement compare( o Takes two Object as argument: compare(Object o1,Object o2) ●And returns ONegative value if o1 is less than o2 OZero value if o1 is equal to o2 Opositive value if o1 is greater than o2
Comparator interface lTwo methods: compare(), equals() lOnly need to implement compare() lTakes two Object as argument: compare(Object o1, Object o2) lAnd returns ¡Negative value if o1 is less than o2 ¡Zero value if o1 is equal to o2 ¡positive value if o1 is greater than o2

Sort example:WorkerTest.java
Sort example: WorkerTest.java
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 上海交通大学:《操作系统 Operating System》课程教学资料(JAVA PPT)lec3.ppt
- 上海交通大学:《操作系统 Operating System》课程教学资料(JAVA PPT)lec2.ppt
- 上海交通大学:《操作系统 Operating System》课程教学资料(JAVA PPT)lec1.ppt
- 上海交通大学:《操作系统 Operating System》课程教学资料(Java)Java Introduction.docx
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-thread.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-OPERATING SYSTEMS(LINUX SYSTEM CALLS).pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-semaphore EXERCISES.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-process_Lec8.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-process_Lec7.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-process_Lec6.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-process_Lec5.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-process_Lec4.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Process Synchronization_Lec14.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Process Synchronization_Lec13.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Process Synchronization_Lec12.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Lec24_Review.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Lec24_DISK MANAGEMENT AND I/O.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Lec23_file system implementation.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Lec22_file system implementation.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资源(课件讲稿)OS-Lec21_file system interface.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资料(JAVA PPT)lec5.ppt
- 上海交通大学:《操作系统 Operating System》课程教学资料(Java)Java Primer.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资料(Java)Java多线程应用实例(制作烟花效果).doc
- 上海交通大学:《操作系统 Operating System》课程教学资料(Java)Java多线程编程.pdf
- 上海交通大学:《操作系统 Operating System》课程教学资料(Java)JAVA多线程编程详解(详细操作例子).doc
- 上海交通大学:《操作系统 Operating System》课程教学资料(Java)Java学习笔记(JAVA的面向对象编程——课堂笔记).doc
- 上海交通大学:《操作系统 Operating System》课程教学资料_管程.docx
- 上海交通大学:《操作系统 Operating System》课程教学资料_往年试卷.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture01.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture02.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture03 CONDITIONALS AND SEQUENCES Strings, lists and file objects.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture04 MODULAR PROGRAMMING Functions.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture05 ITERATION Control Structure.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture06 OBJECTS AND GRAPHICS GUI.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture07 OBJECT ORIENTED DEVELOPMENT Class and Object.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture08 DATA COLLECTION Massive data representation and processing.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture09 SIMULATION AND DESIGN Real-world problem.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Lecture10 ALGORITHM DESIGN AND ANALYSIS To the Classic.pdf
- 上海交通大学:《Computational Thinking and Approach》教学资源(课件讲稿)Something You Should Know.pdf
- 上海交通大学:《C++程序设计与实践》课程教学资源(学习资料)C++练习(题目).pdf