我@Jonny亨利同意,一個簡單的ArrayList
documentation查找應該足夠在這裏,但,萬一海報是一個新手,這裏的我的答案。
// Your code
ArrayList<Object> obj=new ArrayList<Object>();
ArrayList<Object> obj2=new ArrayList<Object>();
obj2.add(101);//contain core data
obj.add(obj2);//storing obj2 into the obj
// My code: Get 101 from obj2
// Because obj2 is in-scope here, and assuming that you know
// obj2 is not empty...
Object data = obj2.get(0);
// Above, data will be an Integer object due to auto-boxing
// If it is null, auto-unboxing will throw NullPointerException
// If data == null, set dataInt to any value to indicate that.
// Here, I am setting it to -1, assuming -1 is an invalid value
// for your application.
int dataInt = (data != null) ? data : -1;
請參閱'ArrayList's'文檔,這是一個簡短的谷歌搜索了。 –