How can I convert ArrayList<Object> to ArrayList?

后端 未结 11 791
-上瘾入骨i
-上瘾入骨i 2020-11-28 06:31
ArrayList list = new ArrayList();
list.add(1);
list.add(\"Java\");
list.add(3.14);
System.out.println(list.toString());


11条回答
  •  北海茫月
    2020-11-28 07:17

    If you want to do it the dirty way, try this.

    @SuppressWarnings("unchecked")
    public ArrayList convert(ArrayList a) {
       return (ArrayList) a;
    }
    
    
    

    Advantage: here you save time by not iterating over all objects.

    Disadvantage: may produce a hole in your foot.

    提交回复
    热议问题