How to insert an object in an ArrayList at a specific position

后端 未结 7 1218
挽巷
挽巷 2020-11-29 22:08

Suppose I have an ArrayList of objects of size n. Now I want to insert an another object at specific position, let\'s say at index position k (is greater than 0 and less tha

7条回答
  •  感情败类
    2020-11-29 22:28

    This method Appends the specified element to the end of this list.

    add(E e) //append element to the end of the arraylist.
    

    This method Inserts the specified element at the specified position in this list.

    void add(int index, E element) //inserts element at the given position in the array list.
    

    This method Replaces the element at the specified position in this list with the specified element.

    set(int index, E element) //Replaces the element at the specified position in this list with the specified element.
          
    
          
    

提交回复
热议问题