开发者社区> 问答> 正文

将数组转换为ArrayList

我在将数组转换为ArrayListJava 中时遇到很多麻烦。这是我现在的数组:

Card[] hand = new Card[2]; “手”持有一系列“卡”。这看起来像ArrayList什么? 问题来源于stack overflow

展开
收起
保持可爱mmm 2020-02-08 14:27:10 459 0
1 条回答
写回答
取消 提交回答
  • 作为ArrayList那条线将是

    import java.util.ArrayList; ... ArrayList hand = new ArrayList (); 要使用ArrayList你所拥有的

    hand.get(i); //gets the element at position i hand.add(obj); //adds the obj to the end of the list hand.remove(i); //removes the element at position i hand.add(i, obj); //adds the obj at the specified index hand.set(i, obj); //overwrites the object at i with the new obj

    2020-02-08 14:27:19
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载