How to check if an Object is a Collection Type in Java?

前端 未结 6 762
栀梦
栀梦 2020-12-12 18:49

By using java reflection, we can easily know if an object is an array. What\'s the easiest way to tell if an object is a collection(Set,List,Map,Vector...)?

6条回答
  •  伪装坚强ぢ
    2020-12-12 19:26

    Test if the object implements either java.util.Collection or java.util.Map. (Map has to be tested separately because it isn't a sub-interface of Collection.)

提交回复
热议问题