Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中判断isInstance(ArrayList<;>;)_Java_List - Fatal编程技术网

如何在java中判断isInstance(ArrayList<;>;)

如何在java中判断isInstance(ArrayList<;>;),java,list,Java,List,在Java中如何判断变量是否是ArrayList?与isInstance函数类似。只需使用instanceof,blow是一个非常简单的示例,如何检测变量是ArrayList: List<String> strings = new ArrayList<>(); if (strings instanceof ArrayList) { System.out.println("ArrayList"); } List strings=new ArrayList();

在Java中如何判断变量是否是ArrayList?与isInstance函数类似。

只需使用
instanceof
,blow是一个非常简单的示例,如何检测变量是ArrayList:

List<String> strings = new ArrayList<>();

if (strings instanceof ArrayList) {
    System.out.println("ArrayList");
}
List strings=new ArrayList();
if(字符串实例为ArrayList){
System.out.println(“ArrayList”);
}
a.getClass().getName()将为您提供变量值的类型,但不是变量的类型

boolean b=String的instanceof
-将告诉您它是否是特定类的实例

我从以下信息中获得了这些信息:如何知道java中的变量类型

这是可能发生的。我正在尝试将字符串解析为int,我想知道我的
Integer.parseInt(s.substring(a,b)
在我尝试求和之前是否正在踢出int或垃圾。

“类似于isInstance函数。” >你的意思是 运算符吗?使用它常常暗示代码可能有气味,这个问题实际上可能是XY问题,最好的解决方案是完全用另一条路线来解决。考虑告诉我们你正在试图解决的总体问题,而不是你现在如何尝试SOL。我相信它。