Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,162,329 members, 7,850,178 topics. Date: Tuesday, 04 June 2024 at 03:46 PM

Java Collection Question - Programming - Nairaland

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

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

(1) (Reply) (Go Down)

Java Collection Question by mludwig01: 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(m): 3:14pm On Jun 01, 2010
What program do you have in mind?

(1) (Reply)

Naira.com / How Do I Use This In Several Programs / Php/mysql

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.