Search code examples
javaandroidarraysequivalent

What is the Equivalent code From array_push in java?


Hi guys I need the equivalent java code of this PHP code:

<?php
  $stack = array("orange", "banana");
  array_push($stack, "apple", "raspberry");
  print_r($stack);
?>

the Output is:

Array
(
    [0] => orange
    [1] => banana
    [2] => apple
    [3] => raspberry
)

Solution

  • You have to use a ArrayList.

    List<String> list = new ArrayList<String>();
    list.add("orange");
    list.add("banana");