Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,332 members, 7,808,134 topics. Date: Thursday, 25 April 2024 at 07:36 AM

Which One's D Most Effective: Map,hashmap,lists - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Which One's D Most Effective: Map,hashmap,lists (835 Views)

Create A Nested Lists Of Categories In Laravel 5 / Which Is The D Most Lucrative Language....programmers ASSEMBLE!! / Why Nigerian Software Firms Are Absent On The Global Map (2) (3) (4)

(1) (Reply) (Go Down)

Which One's D Most Effective: Map,hashmap,lists by Danyl(m): 7:44am On Feb 21, 2013
Gudmornin NLders,am having some issues with a program that requires storing selected values into a datastructure. I used the Map interface- Map answerMap=new HashMap(); since the Map interface cannot be instantiated. When i wanted to get the key-value pairs stored in d map, only one element was stored. What could b problem. I tot of using a HashMap<Integer, String> aMap = new HashMap<Integer, String>() to handle d problem perhaps that'll solve. When i usd List, it worked bt it allows duplicate entries which I don't want..how best can i go abt dis. I don't duplicate entries in the datastructure. Thanks.
Re: Which One's D Most Effective: Map,hashmap,lists by Javanian: 8:55am On Feb 21, 2013
I think you are just playing around with these data structures. A map and a list have different uses, each has its strength and weakness. It all depends on what you are trying to acheive. If the size of the data is known, then a list is even an overkill. You could have just used a simple array. Maps are mostly used when you want to store data in a key-value system. It could be a hash map, TreeMap a dictionary e.t.c. I don't know if there is a data structure that would efficiently help you in what you are trying to acheive but to find duplicates in your data structure you can search through it for duplicates before inserting. I suggest you use something like a binary search which would run in O(logN) time (i think) but its way better than looping through it which would run in O(N) time at best case. But for effieciency you would have to sort the data with preferably a quick sort or anyother type of sort before searching.


I think there is a data structure like a set(Set, HashSet and linkedHashSet) that doesn't allow duplicates. I once used it, you can go with this if you are looking for an easy way out but am not too sure of the efficiency...Hope this helps...
Re: Which One's D Most Effective: Map,hashmap,lists by sunnyben: 12:57pm On Feb 21, 2013
Map, Set and Lists are made for different purposes. Map is for key-value pair storage, List works like an dynamically expandable array while Set is like the List, but doesn't allow duplicates.
Re: Which One's D Most Effective: Map,hashmap,lists by Danyl(m): 3:26pm On Feb 21, 2013
Javanian: I think you are just playing around with these data structures. A map and a list have different uses, each has its strength and weakness. It all depends on what you are trying to acheive. If the size of the data is known, then a list is even an overkill. You could have just used a simple array. Maps are mostly used when you want to store data in a key-value system. It could be a hash map, TreeMap a dictionary e.t.c. I don't know if there is a data structure that would efficiently help you in what you are trying to acheive but to find duplicates in your data structure you can search through it for duplicates before inserting. I suggest you use something like a binary search which would run in O(logN) time (i think) but its way better than looping through it which would run in O(N) time at best case. But for effieciency you would have to sort the data with preferably a quick sort or anyother type of sort before searching.


I think there is a data structure like a set(Set, HashSet and linkedHashSet) that doesn't allow duplicates. I once used it, you can go with this if you are looking for an easy way out but am not too sure of the efficiency...Hope this helps...
thanks 4dat piece,actually am building a kinda Q & A engine and arrays wönt handle d problem,der will b times wen i might want to remove an element frm d storage,dats not possible with array, List should do it but I'm looking 4 a datastructure dat stores using a key-value mapping that is y i used Maps in d first plc. Searching for key value pairs workd on it, but when trying to print the all d stored key-value entries only one record ws returned,so am trying 2figure a way out.
Re: Which One's D Most Effective: Map,hashmap,lists by Javanian: 4:06pm On Feb 21, 2013
Danyl:
thanks 4dat piece,actually am building a kinda Q & A engine and arrays wönt handle d problem,der will b times wen i might want to remove an element frm d storage,dats not possible with array
,

Wrong! It is possible. Just that using a list in the java.util package is easier and would save more time...

List should do it but I'm looking 4 a datastructure dat stores using a key-value mapping that is y i used Maps in d first plc. Searching for key value pairs workd on it, but when trying to print the all d stored key-value entries only one record ws returned,so am trying 2figure a way out.

well, i don't know exactly what you have in mind to acheive but if it is the Q and A game i have in mind, i see no reason why i should use a map...all the same use what ever works...
Re: Which One's D Most Effective: Map,hashmap,lists by Danyl(m): 8:24pm On Feb 21, 2013
@javanian, tnx 4ur contributions. I think with an ArrayList u cn delete an element at a specified position bt with a/an string or any oda primitive array, not that i know of... Wat i intended to do wit d datastructure is to add the answers with the question serial no/index in the datastructure for a final review...getting d final score of users can also be accessed frm dat.

(1) (Reply)

What Will It Cost To Create A Secure Financial Portal? / Pls Can Som1 Giv Me A Link To Download Free Netbeans IDE Free? / I Need Help In Installing CS5

(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. 21
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.