⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 collectionclassifier2.java

📁 effective-java中文英文版,大师人物写的
💻 JAVA
字号:
// Working collection classifier - Page 130

import java.util.*;

public class CollectionClassifier2 {
    public static String classify(Collection c) {
        return (c instanceof Set ? "Set" :
                (c instanceof List ? "List" : "Unknown Collection"));
    }

    public static void main(String[] args) {
        Collection[] tests = new Collection[] {
            new HashSet(),          // A Set
            new ArrayList(),        // A List
            new HashMap().values()  // Neither Set nor List
        };

        for (int i = 0; i < tests.length; i++)
            System.out.println(classify(tests[i]));
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -