Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我创建了一个对象的 ArrayList,它包含整数和字符串。
List<Object> arrayList = new ArrayList<>();
使用以下条件,我检查了它是否为整数
if(arrayList.get(indexValue) instanceof Integer){ // Here how convert the object into integer }
但问题是,如何将对象转换为整数?
谢谢
您可以将其显式转换为 Integer,但不需要 Java 为您完成。
if(arrayList.get(indexValue) instanceof Integer){ Integer i = arrayList.get(indexValue); }