TheArrayListClass.pdf
《TheArrayListClass.pdf》由会员分享,可在线阅读,更多相关《TheArrayListClass.pdf(5页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、The Array List Class Introduction to the Collections Framework or Using the Library My goals with this chapter Be exposed to the Collection Frameworks by looking at the ArrayList class in the library Learn what linked lists are and how to program them Become familiar with the LinkedList class in the
2、 library and see the advantages of using it To become familiar with Iterators and their importance Use the LinkedList class with a generic type The Java Collections Framework An Overview A collection is A group of related data elements,organized into a single object With operations provided to manip
3、ulate the data So far,the only collection we have used is the array.The most common collections are implemented as arrays,linked lists,or trees There are variations on these basic types Using the collections framework reduces your programming effort and increases performance.It implements many usefu
4、l data structures and algorithms The collection framework consists of:Collection Interfaces these interfaces form the basis of the framework They specify methods that must be implemented in classes that implement the interface General-purpose Implementations Classes like ArrayList and LinkedList Abs
5、tract Implementations Partial implementations to make custom collections easier to implement Algorithms Static methods to perform useful functions on collections,such as sorting a list Java predefined Collection interfaces Collection interface One of Collections methods returns an Iterator List inte
6、rface is a sub interface of Collection It has methods that apply specifically to lists Iterator interface It has three easy-to-use methods ListIterator interface is subinterface Iterator The List Interface A list is an expandable collection of elements in which each element has a position or index T
7、here are various ways of storing lists on the computer Some can be accessed in arbitrary order(random access).Some can only be accessed sequentially.Some keep the list sorted by their very nature.Regardless of the way the list is stored,there are certain activities we want to do with every list Add
8、to the list;remove from the list;find an item,etc.Using the general purpose implementations Among others,the library contains a class LinkedList and a class ArrayList Using these predefined classes is easier,faster,and less error prone than writing your own.Much thought has been given to the methods
9、 and their implementation in these prewritten classes And,of course,they are bug free But you must know how to use them Abstract classes,Interfaces and Iterators play a big role in the prewritten classes Using the Array List Class Usually,a list contains one type of data The ArrayList class is expec
10、ts you to say what type of data will be in the class This is done using angle brackets List=new ArrayList();Remember,this is call to the constructor,so dont forget the parentheses.In the Java API the class name is ArrayList The stands for the type of stored in the ArrayList If you do not specify the
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- TheArrayListClass
限制150内