₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,903 members, 8,424,133 topics. Date: Wednesday, 10 June 2026 at 06:09 PM

Toggle theme

Java Collection Question - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingJava Collection Question (762 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 Gurus234

I Need A Tutor In Web Design And Other Related Programme In Lagos.HTML 5 Canvas AminationsWhat Are The Basic Features Of Java Programming Language