When to use a List over an Array in Java? -


In Java, when would it be preferable to use a list instead of arrays?

I see the question as the reverse-

When should an array be used?

Only you have a specific reason to do this (examples: project prevention, memory concerns (there really is no good reason), etc.)

Using Lists There is more functionality (IMO), more functionality

Note: You should also consider whether there is nothing like a set, or a better fit than the list of any other datastructure.

Each data structure, and implantation, various professionals / Opposition is to select the things that you get excellently in the things you need to do.

If you (1) need to get (1) for any object? Possibly use an ArrayList, insert the requirement (1) of O ()? Probably a linked list o (1) is required ()? Probably a hashet.

TLDR: Each data structure is good in some things, and is bad on others. See your objectives and choose the data structure that is better than the given problem.

Edit:

It does not matter if you are better your interface (ie list or queue) as its variable instead of its implementation class To declare. In this way, you can change the implementation at some later date without changing anything in the code.

As an example:

  list & lt; String & gt; MyList = new Arsèchchi & lt; String & gt; ();  

versus

  list & lt; String & gt; MyList = New Linkedist & lt; String & gt; ();  

Note that myList is a list in both instances. - R. Bamos


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -