m mới bắt đầu học java nên chưa có kinh nghiệm gì, nên mong các tiền bối đi trước cho em vài lời khuyên. trước đây em có học qua về c++ với C và php nhưng không thực sự giỏi cái nào. hiện nay em đang có bài tập lớn về java,mà em thì không có kinh nghiệm gì về nó nên muốn chọn mảng nào dễ hơn để có thể dễ bắt đầu, nếu các anh chị nào đã học qua thì cho em 1 vài lời khuyên với.em xin cám ơn các anh chị trước.
JPII, Session 4 Module 5 - java.util and Collections API Module4 - Review Advanced Java / Session4 / 2 of 27 A Guide To Advanced Java – Module 4 2 • A stream is a logical entity that produces or consumes information. • Data stream supports input/output of primitive data types and String values. • InputStream is an abstract class that defines how data is received. The OutputStream class is also abstract, it defines the way in which output is written to streams. • File class directly works with files on the file system • A buffer is a temporary storage area for data • Character streams provide a way to handle character oriented input/output operations • Serialization is the process of reading and writing objects to a byte stream (Using ObjectInputStream/ObjectOutputStream) Objectives Advanced Java / Session4 / 3 of 27 A Guide To Advanced Java – Module 5 Collections are very important Java Collection API “If you can program with Java but you don't understand interfaces yet, you may have some trouble getting through the material in this session.” “The topics such as linked lists, queues, stacks, and binary trees, among many other data structures are related topic for this session.” Introduction to java.util package • The java.util package contains the definition of a number of useful classes providing a broad range of functionality • Collections Framework belongs to this package. It consists of interfaces and classes for working with group of objects. Advanced Java / Session4 / 4 of 27 A Guide To Advanced Java – Module 5 Overview of Collection A collection is a group of data manipulate as single object. Corresponds to a b ag. Can grow as necessary Heterogeneous Can be made thread safe (concurrent access) Can be made not-modifiable. Advanced Java / Session4 / 5 of 27 Array vs Collection Array o Holds objects of known type. o Fixed size Collections o Generalization of the array concept. o Set of interfaces defined in Java for storing object. o Multiple types of objects. o Resizable. Advanced Java / Session4 / 6 of 27 Collection Interfaces Collections are primarily defined through a set of interfaces. Supported by a set of classes that implement the interfaces Advanced Java / Session4 / 7 of 27 Some methods of “Collection” interface -1 Advanced Java / Session4 / 8 of 27 o int size() Returns the number of elements in this collection. o boolean isEmpty() Returns true if this collection contains no elements. o boolean contains(Object element) Returns true if this collection contains the specified element o boolean add(Object element) Ensures that this collection contains the specified element o Iterator iterator() Returns an iterator over the elements in this collection. Iterator -1 An iterator is an object that allows to traverse through all the elements of a collection, regardless of its specific implementation An iterator is sometimes called a cursor No need for index Advanced Java / Session4 / 20 of 27 [...]... Advanced Java / Session4 / 27 of 27 Guide To Advanced Java – Module 5 A Module5 - Summary We have learnt • Collection, List, Set, Queue, Iterator and some of their implementations • Map and SortedMap interfaces and some of their implementations • Collections, Arrays class A Guide To Advanced Java – Module 5 Q&A A Guide to Advanced Java Java Collection Advanced Java / Session1 / 32 of 33Guide To Advanced Java. .. such as double Its size increases automatically Is best suited for random access without add and remove operations Advanced Java / Session4 / 11 of 27 Guide To Advanced Java – Module 5 A ArrayList • Demo ArrayListExample Advanced Java / Session4 / 11 of 27 Guide To Advanced Java – Module 5 A Vector The Vector class is similar to an ArrayList as it also implements dynamic array The difference between... Advanced Java / Session4 / 25 of 27 Guide To Advanced Java – Module 5 A PriorityQueue class Priority queues similar to queues but the elements are not arranged in FIFO structure They are arranged in a user-defined manner The elements are ordered either by natural ordering or according to a comparator A priority queue is unbound and allows the queue to grow in capacity Advanced Java / Session4. .. grow in capacity Advanced Java / Session4 / 26 of 27 Guide To Advanced Java – Module 5 A Arrays class • Array class provide a number of methods for working with arrays such as searching, sorting and comparing arrays • The important methods are equals(), fill(), sort(), toString() Advanced Java / Session4 / 27 of 27 Guide To Advanced Java – Module 5 A Collections class • Collections class provide a number... calling these methods Advanced Java / Session4 / 11 of 27 Guide To Advanced Java – Module 5 A LinkedList LinkedList implements the List interface • addFirst(E obj) • addLast(E obj) • getFirst() • getLast() • removeFirst() • removeLast() Gives better performance on add and remove vs ArrayList Gives poorer performance on get and set vs ArrayList A Guide To Advanced Java – Module 5 Set interface Corresponds... implements the concept of hash table and the linked list in the Map interface Important methods of the LinkedHashMap class are clear(), containsValue(), get(), removeEldesEntry() Advanced Java / Session4 / 16 of 27 Guide To Advanced Java – Module 5 A HashTable Map map = new HashMap(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); map.put(4, "four"); map.put(5, "five"); //tra ve tap key luu trong... Advanced Java – Module 5 Set classes HashSet class implements the Set interface, a HashSet creates a collection that makes use of a hash table for data storage LinkHashSet class creates a list of elements and maintains the order of elements added to the Set TreeSet class implements the Set interface and uses the tree structure for data storage Objects are stored in ascending order Advanced Java / Session4. .. the tree structure for data storage Objects are stored in ascending order Advanced Java / Session4 / 22 of 27 Guide To Advanced Java – Module 5 A Set Idioms Map interface -1 A Map is an object that maps keys to values, a map cannot contain duplicate keys A Guide To Advanced Java – Module 5 Map interface -2 Methods for adding and deleting o put(Object key, Object value) o remove (Object key) Methods... Methods to retrieve the keys, the values, and (key, value) pairs o keySet() // returns its set of keys o values() // returns a Collection of values o entrySet() // returns a set of entry Advanced Java / Session4 / 15 of 27 Map classes • HashMap implememts Map • Hashtable class stores elements as a key/value pairs in the hash table • TreeMap class stores elements as tree structure and returns keys... A Guide To Advanced Java – Module 5 List interface Extensions compared to the Collection interface Access to elements via indexes, like arrays add (int, Object), get(int), remove(int), set(int, Object) Search for elements indexOf(Object), lastIndexOf(Object) Specialized Iterator, call ListIterator Extraction of sublist subList(int fromIndex, int toIndex) A Guide To Advanced Java – Module 5 ArrayList . many other data structures are related topic for this session.” Introduction to java .util package • The java .util package contains the definition of a number of useful classes providing a broad. JPII, Session 4 Module 5 - java .util and Collections API Module4 - Review Advanced Java / Session4 / 2 of 27 A Guide To Advanced