我創建了Object的ArrayList,它包含Integer和String。將對象arrayList對象轉換爲整數
List<Object> arrayList = new ArrayList<>();
使用下面的條件我檢查它是否是整數或不
if(arrayList.get(indexValue) instanceof Integer){
// Here how convert the object into integer
}
但問題是,我怎麼能轉換對象變成整數?
謝謝
由於您確定該對象是Integer類型的,因此您可以簡單地Cast它! –
使用Integer i = Integer.valueOf(someObject);'http://docs.oracle.com/javase/6/docs/api/java/lang/Integer.html#valueOf (int) – Zaki