java howto ArrayList 推送、弹出、移位和取消移位 [英] java howto ArrayList push, pop, shift, and unshift

查看:26
本文介绍了java howto ArrayList 推送、弹出、移位和取消移位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经确定 Java ArrayList.add 类似于 JavaScript Array.push

I've determined that a Java ArrayList.add is similar to a JavaScript Array.push

我一直在寻找类似于以下的 ArrayList 函数

I'm stuck on finding ArrayList functions similar to the following

  • Array.pop
  • Array.shift
  • Array.unshift 我倾向于 ArrayList.remove[At]
  • Array.pop
  • Array.shift
  • Array.unshift I'm leaning toward ArrayList.remove[At]

推荐答案

ArrayList 的命名标准是独一无二的.以下是等效项:

ArrayList is unique in its naming standards. Here are the equivalencies:

Array.push    -> ArrayList.add(Object o); // Append the list
Array.pop     -> ArrayList.remove(int index); // Remove list[index]
Array.shift   -> ArrayList.remove(0); // Remove first element
Array.unshift -> ArrayList.add(int index, Object o); // Prepend the list

请注意,unshift 不会删除一个元素,而是将一个元素添加到列表中.另请注意,Java 和 JS 之间的极端情况行为可能有所不同,因为它们都有自己的标准.

Note that unshift does not remove an element, but instead adds one to the list. Also note that corner-case behaviors are likely to be different between Java and JS, since they each have their own standards.

这篇关于java howto ArrayList 推送、弹出、移位和取消移位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆