Summary: This section describes the classic example of generics, auto-boxing, iteration, Bag, Queue, stack, and a stack use case-evaluation of arithmetic expressions.
Focus:
1. A key feature of the abstract data types of collection classes is that we should be able to use them to store any type of Data. A special Java mechanism is able to do this, known as generics, also called parameterized Types.
2. When working with assignment statements, method arguments, and arithmetic or logical expressions, Java is automatically referenced in the reference type (Character, Integer ...). ) and the corresponding raw data type (char, int ... ) and convert between Them.
Auto Boxing: Int--Integer
Auto-unpacking: Integer--int
3. If the collection is iterative, the use case can print a list of transactions with a single line of statements:
for (Transaction t:collection) { stdout.println (t);}
This syntax is called a foreach statement: you can treat the for statement as a per-trade T (foreach) in the collection, executing the following code Snippet.
It's hard to imagine a clearer and more concise code than This.
4. A backpack is a collection data type that does not support removing elements from it-its purpose is to help the use case to collect elements and iterate through all the collected elements (use cases can also check whether the backpack is empty or get the number of elements in the backpack).
Using bag can indicate that the order in which elements are processed is Unimportant.
5. A classic reason to use a stack iterator in an application is to reverse their relative order while preserving the elements with the Collection.
6. Evaluation algorithm of double stack arithmetic expression of Dijkstra
Cow!
Algorithm (4th Edition) -1.3.1 API