69.5k views
3 votes
Assume that an ArrayList of Integers named salarySteps that contains exactly five elements has been declared and initialized. Write a statement that assigns the value 160000 to the last element of the ArrayList salarySteps.

User Rob Hughes
by
5.3k points

1 Answer

4 votes

Answer:

Following are the statement to this question:

//using set and size in-built method

salarySteps.set(salarySteps.size()-1, 160000); //assign value at the last element of the list

Step-by-step explanation:

Description of the above can be described as follows:

  • In the question, it is declared, that an array list "salarySteps", is defined, which contains five integer elements, in this array-list at the last we insert an integer value, which is "160000".
  • In the above code, the array list "salarySteps" uses a set method, inside this method a size method is used, that inserts the value "160000" at the last element of the array list.
User Hannah Vernon
by
5.6k points