I’ve determined that a Java ArrayList.add
is similar to a JavaScript Array.push
I’m stuck on finding ArrayList
functions similar to the following
Array.pop
Array.shift
Array.unshift
I’m leaning towardArrayList.remove[At]
Advertisement
Answer
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
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.