android - reverse the order of an array

后端 未结 4 1954
死守一世寂寞
死守一世寂寞 2020-12-14 05:43

I have an array of objects.

Is it possible to make a new array that is a copy of this array, but in reverse order? I was looking for something like this.

         


        
4条回答
  •  孤城傲影
    2020-12-14 05:55

    Simple approach without implementing anything.

                    ArrayList oldlist = new ArrayList();
                    ArrayList newList = new ArrayList();
                    int size = oldlist.size()-1;
    
                    for(int i=size;i>=0;i--){
                        newList.add(oldlist.get(i));
                    }
    

提交回复
热议问题