java - Efficient way to get/remove first element from the list? -


i want take out , remove first element list. can see, have 2 options:

first approach:

linkedlist<string> servers = new linkedlist<string>(); .... string firstservername = servers.removefirst(); 

second approach

arraylist<string> servers = new arraylist<string>(); .... string firstservername = servers.remove(0); 

i have lot of elements in list.

  • is there preference 1 should use?
  • and difference between above two? technically same thing in terms of performance? complexity involve here if have lot of elements?

what efficient way this.

make sure understand difference between linkedlist , arraylist. arraylist implemented using array.

linkedlist takes constant time remove element. arraylist might take linear time remove first element (to confirm need check implementation, not java expert here).

also think linkedlist more efficient in terms of space. because arraylist not (and should not) re-size array every time element removed, takes more space needed.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Website Login Issue developed in magento -

Can the constants be defined inside a model file of a framework in PHP? -