提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
检查对象是否为集合的方法。
/**来自 NowJava.com - 时 代 Java**/ //package com.book2s; import java.util.*; public class Main { public static void main(String[] argv) { Object ob = "book2s.com"; System.out.println(isCollection(ob)); } /** * Method to check if a Object is a Collection or not. * @param ob the Object to inspect. * @return if true the class extend or implememnt Collection. */ public static boolean isCollection(Object ob) { return ob instanceof Collection || ob instanceof Map; /**