[DataStructure] The description of generic collections, datastructure

Source: Internet
Author: User

[DataStructure] The description of generic collections, datastructure

In this blog, generic collections will be talked about in details. in the past bacause of temporary age of generic argument, less importance has been attached to the this module. just now after reading the chapter about this knowledge, I gradually realized that they are so useful in the pactice, especially desgin the system achitect. now make a summary about generic collections.

First, use the type argument

package com.albertshao.ds.generic;public class EnumArgument {enum Week {Mon, Tus, Wed, Thu, Fri, Sta, Sun}public static void main(String args[]){Pair<Integer, Week> pairs = new Pair<Integer, Week>(2, Week.Mon);System.out.println(pairs);}}class Pair<S, T> {private S first;private T second;public Pair(S first, T second){this.first = first;this.second = second;}public S getFirst() {return first;}public void setFirst(S first) {this.first = first;}public T getSecond() {return second;}public void setSecond(T second) {this.second = second;}public String toString(){return "("+first + "," + second+")";}}/** * output:(2,Mon) */
Second, use the generic methods

In addition to generic types, type parameters can also be used to define generic methods, identified by the generic parameter specifier <T> placed in front of the return type.

package com.albertshao.ds.generic;public class TestPrint {public static void main(String[] args) {String[] weeks = new String[] { "Mon", "Tus", "Wed" };print(weeks);}static <E> void print(E[] a) {for (E e : a) {System.out.println(e);}}}/* * output: * Mon * Tus * Wed *  */

Third, use generic wildcards

The symbol? Can be used as a wildcard, in place of a generic variable. It stands for "unknown type," and is called the wildcard type.

package com.albertshao.ds.generic;import java.util.Arrays;import java.util.Collection;import java.util.List;public class TestWildCards {public static void main(String[] args) {List<String> strList = Arrays.asList("Fri", "Sat", "Sun");print(strList);}static void print(Collection<?> c) {for (Object o : c) {System.out.printf("%s ", o);}System.out.println();}}// output: Fri Sat Sun 








Hence the description of america as a "graveyard" for ages help translate and talk about its sentence structure.

Hence the description of america as a "graveyard" for ages.
Therefore, the United States is hailed as the grave of language.

Analyzing sentence structures is not my strength. However, this sentence is not complicated. Use description of america as the subject (this seems to be a compound subject ). In fact, if you change the sentence: somebody described america as a "graveyard" for ages.

How to enter ATAS brief description of the subjects covered

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.