₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,456 members, 8,512,028 topics. Date: Monday, 02 November 2026 at 04:53 PM

Toggle theme

Java Collection Question - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Java Collection Question (775 Views)

1 Reply (Go Down)

Java Collection Question by mludwig01(op): 9:27pm On May 25, 2010
When talking about Java Collections:

- How long does it take to add an element to :
* a map
* a list
- How long does it take to find an element from:
* list
* array
* sorted list
* sorted array
* tree
* hashmap
- How long does it take to sort a list of n elements







***I'm new to technology so thank you so much for your answers/help and thanks for bearing with me!***
Re: Java Collection Question by logica(m): 11:12pm On May 25, 2010
Why don't you write a program to check all these?
Re: Java Collection Question by candylips(m): 1:29pm On May 26, 2010
The time taken is related to their relative complexity

- How long does it take to add an element to :
    * a map - constant
    * a list - constant
- How long does it take to find an element from:
    * list -  depends on the algorithm . . binary search or linear search
    * array - same as list
    * sorted list - linear if u do a linear search. But binary search is faster
    * sorted array - as as sorted list
    * tree - quadratic
    * hashmap - constant
- How long does it take to sort a list of n elements
  Depends on the sort algorithm you use. Quick or Merge sort are usually the fastest

So if you are concerned about speed the best datastructure to use is a Hashmap/Hashtable (although they are not suitable for most uses) because they are the fastest for addition and retreival of elements
Re: Java Collection Question by Seun(mod): 3:14pm On Jun 01, 2010
What program do you have in mind?
1 Reply

Laravel:call To Undefined Method Illuminate\database\eloquent\collection::save() • Collection Of Nigerian Programming Gurus • 2 • 3 • 4

In Need Of Knowledge • I Challenge You (high Octave Programmers) • Game Development: 2D Multiplatform Game