(JAVA in the following order of priority
· Goal-oriented
·Class set structure
·JDBC
·File programming
Program this season
First explain the following:
·Collection
·List
·Set
·Map
·Iterator
·ListIterator
·Enumeration
·for...each sentence (new feature of JDK1.5)
Comparable interface
·Binary tree
1. Class set structure
(1) The purpose of generating the set
The class set is simply a dynamic target array, the target array can be changed in size, and the addition, deletion and output of the target can be arbitrarily terminated. All classes are stored in the java.util package.
(2) Differences in class sets
1. Consignment single value: Collection
2. Register a pair of values: Map
3. Output: Iterator
(3) Detailed concept of class set
lt;1gt;Collection (only one value can be registered)
- Primary function: for output use
- Sub-interface <imgsrc="sweat.gif"smilieid="10"border="0"alt=""/>ist (repeated elements are allowed, and the order of participation is the order of output)
-Subclass: ArrayList, which was launched after Java2, is a new class, uses asynchronous management, and has higher functions
-Subclass: Vector, which was launched in JDK1.0. Because it is an old class, it has many functions that List does not have. It uses the synchronization management method, and its thread safety is high and it will be slower. In addition to using the Iterator output, you can also use the Enumeration for output. Both are generic. The Vector subclass allows direct use of addElement(Objectobj), and can also add elements to the collection.
-Added methods by yourself:
- Take each object: publicObjectget(intind);
- Subclass: Stack (stack)
- Sub-interface: Set (repeated elements are not allowed, repeated elements will be replaced)? How can we distinguish repeated elements?
- Subclass: HashSet: is an unordered register
- Subclass: TreeSet: Ordered storage, which is terminated through the Comparable interface
-Common method:
- add an object: publicbooleanadd(Objectobj)
- Get the length of the class set: publicintsize();
- Determine whether the content in the set is empty: publicbooleanisEmpty()
-Deleting an object: publicbooleanremove(Objectobj): must involve the comparison of the object.
- Instantiate the Iterator target: publicIteratoriterator();
lt;2gt;JDK1.5 provides a convenient output operation: for...each sentence.
lt;3gt;Iterator interface output is the most common
-Common methods
-publicbooleanhasNext(): Determine if there is a next element
-publicObjectnext(): take out the next element
-The sub-interface <imgsrc="sweat.gif"smilieid="10"border="0"alt=""/>istIterator, which can perform bidirectional output, is only valid for the List interface
-Common methods: with comprehensive content in the Iterator interface
-publicbooleanhasPrevious()
-publicObjectprevious()
lt;4gt;Enumeration (also participate after 1.5, generic support ha~)
-Common method:
- Determine if there is a next element: publicbooleanhasMoreElements()
- Take out elements: publicObjectelement()
5. Map (register a pair of values)
-Function: Unlike the function of Collection, the primary function of Map is for searching.
-be careful:
- When using Map operations, iterator cannot be used directly for output.
-And there cannot be duplicate keys in it.
-If you have to use Iterator for output, you must do the following process:
-Map--gt;Set--gt;Iterator--gt;Map.Entry--gt;The difference between key and value
-Common subclasses:
-HashMap: unordered storage, is a new class, launched in JDK1.2, asynchronous management, high function
-Hashtable: It is an old class, launched when JDK1.0, it is thread-safe and has lower functions
-Properties (points): Properties file operation class
-TreeMap: ordered storage
-Common method:
-Retain data in the call set: publicObjectput(Objectkey, Objectvalue): The value returned is
-Search data from the collection: publicObjectget(Objectkey): Search by key.
- Turn Map data into Set instances: Setlt;Map.Entrylt;K,Vgt;gt;entrySet()
- Turn a comprehensive key into a set instance: Setlt;Kgt;keySet()
- Turn a comprehensive vlaue into an instance of the Collection interface: Collectionlt;Vgt;values()
-Map.Entry: keep key and value
-publicObjectgetKey()
-publicObjectgetValue()
-Notes on storing keys:
################Michael dividing line####################
2. Code Explanation
(11) HashMap
Basic use of Map
If it is found, it will return the detailed value, if it is not found, it will return null
Use Iterator to output the contents of the Map interface
HashSet: It is a non-sequential storage drop~~~
output the full key
output full value
(12) Hashtable
(13)TreeMap
Sorting by key, the Comparable interface is still used in this operation.
TreeSet: Ordered storage, terminated through the Comparable interface
(14) Stack
Push: publicObjectpush(Objectobj)
Pop out: publicObjectpop()
Note: If there is no content in the stack at the moment, an exception will occur.
(15) Properties (points)
·Attribute operation class, all keys and values ??are set according to attributes, which are all strings. And this property file can be directly kept in the file, or read out from the file.
Set properties: publicObjectsetProperties(Stringkey, Stringvalue)
Get properties:
-publicStringgetProperty(Stringkey): Read the property according to the key and return the value
-publicStringgetProperty(Stringkey, Stringdef): If no value is read, return the content specified by def.
Keep in the file:
- Keep as general file: publicvoidstore(OutputStreamout, Stringcomments) throwsIOException
- Preserve as XML file: publicvoidstoreToXML(OutputStreamout, Stringcomments) throwsIOException
Read properties from file:
- Reading from general file: publicvoidload(InputStreaminput) throwsIOException
- Reading from XML file: publicvoidloadFromXML(InputStreaminput) throwsIOException
Keep the content as a regular file:
Keep the content as an XML file:)