4) knowledge about JAVA containers and java containers

Source: Internet
Author: User
Tags comparable

4) knowledge about JAVA containers and java containers

1> Array and Arrays: Arrays: A Tool class used to operate Arrays. It contains a set of static functions: equals (): Compares whether two Arrays are equal. Array has the same number of elements, and all corresponding elements are equal to each other.
Fill (): Enter the value in array. Sort (): used to sort arrays.
BinarySearch (): Search for elements in the sorted array.
System. arraycopy (): copying an array. 2> Collection and CollectionsCollections. max (Collection coll); obtain the largest element in the Collection.
Collections. sort (List list); sorts the elements in the list.
 
3> Design Pattern and iterator
Iterator: provides a method to sequentially aggregate elements of an object without exposing the internal representation of the object. Its main purpose is 1. different containers provide the same iterator interface. 2. this iterator interface is used when containers are used to access the content inside the container. 3. in this way, you only need to change the Declaration type when changing the container in use. The Code originally written for another container is still fully applicable to the new container.

Java iterator: It has simple functions and can only be moved one way.
(1) The method iterator () requires the container to return an Iterator. When the next () method of Iterator is called for the first time, it returns the first element of the sequence. Note: The iterator () method is a java. lang. Iterable interface inherited by Collection.
(2) Use next () to obtain the next element in the sequence.
(3) Use hasNext () to check whether there are any elements in the sequence.
(4) use remove () to delete the elements returned by the iterator.
Iterator is the simplest implementation of the Java Iterator. The ListIterator designed for List has more functions. It can traverse the List in two directions, or insert and delete elements from the List.

  4> Comparable InterfaceIn the java. lang Package, the Comparable interface is applicable when a class has a natural order. Assuming that the object set is of the same type, this interface allows you to sort the set in a natural order. There are not many classes that implement the Comparable interface:

Class

Sort

BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short

Sort by number

Character

Sort by numbers of Unicode values

CollationKey

Sort by language-sensitive strings

Date

Sort by generation

File

Sort by Unicode values of fully qualified characters of the system-specific path name

ObjectStreamField

Sort by Unicode values of Characters in the name

String

Sort by Unicode values in strings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.