Can someone please provide an example of creating a Java ArrayList and HashMap on the fly? So instead of doing an add() or put(), actually supplying the seed data for the ... |
I'm storing data in a HashMap with (key: String, value: ArrayList). The part I'm having trouble with declares a new ArrayList "current," searches the HashMap for the String "dictCode," and if ... |
I have one million rows of data in .txt format. the format is very simple. For each row:
user1,value1
user2,value2
user3,value3
user1,value4
...
You know what I mean. For each user, it could appear many times, ... |
I have two arraylists A1, A2. Each element of A1 would be the key and each element of A2 the corresponding value. So the solution that I found is looping on ... |
In java, ArrayList and HashMap are using in collections. But i couldn't understand at which situations we should use ArrayList and which time use HashMap. What is the major difference between ... |
I want to fill ArrayList(Appointment_List) with hashmap(Appointment) but each time i need to change the value of specified elements(Appt_Start_Time and End_Time) .
here is the code:
for(int i=1;i< Appt_Length;i++){
Start_Time=End_Time;
...
|
ArrayList<HashMap<String, String>>
arrayListRowsFirst = new ArrayList<HashMap<String, String>>();
Today when i was going through a code, this piece of code struck me for a while. Here are some of my questions over this ... |
|
I tried to create a list of maps. In the following code, I'm expecting to get
[{start=1,text=ye}, {start=2,text=no}]
however, I only got
[{start=2,text=no}, {start=2,text=no}]
How to avoid overriding the first map? Here ... |
I am halfway through debugging a Breadth-First Search algorithm using an adjacency list representation of graph data: HashMap<String, ArrayList<Edge>>. Each String key is the name of an underground station, and each ... |
Say you have a domain class that has an ArrayList attribute. What is the best practise when writing getters and setters for this type of instance (to avoid it being modified)?
... |
I have an ArrayList<HashMap<String, String>>. I'd like to quickly extract from this a new ArrayList<String> comprising all the keys.
How do I do this?
|
I am coming from the world of Perl programming and am unfamiliar with how one would create a list of hashes in Java.
In perl, creating a list of hashes is easy.
@rows ... |
As per Sun Java Implementation, during expansion, ArrayList grows to 3/2 it's initial capacity whereas for HashMap the expansion rate is double. What is reason behind this?
As per the implementation, for ... |
I keep finding a need for a container which is both a HashMap (for fast lookup on a key type) and an ArrayList (for fast access by integer index).
LinkedHashMap is ... |
I need to call an external API with an ArrayList of HashMaps holding several predefined key-value pairs each. An example:
ArrayList<HashMap<String, String>> arrayListHashMap = new ArrayList<HashMap<String, String>>();
{
...
|
I am getting an error message.
Suspicious call to java.util.Map.ContainsValue Given object cannot
contain instance of String (Except ArrayList)
This is a small version of the program that I am ... |
I was told to change everything to HashMap() instead of ArrayList() and for the most part everything worked perfect. However, I am having a problem getting this one method to ... |
I have an ArrayList<String>, the strings of which I'm using as keys in a HashMap<String, ArrayList<Object>>
When I finally put the keys and values in my HashMap, I don't actually know ... |
I am working on a piece of code which has a Hashmap. This hashmap has a string as key and an arraylist as value. I populate the arraylist and then put ... |
I want to store my data in HashMap<Point[], Double>. I used iteration to assign the data, but when I checked at the end, the number of elements is only 1. I ... |
i have following code snippets
ArrayList col = [{name ="ddd",date =10/08/2011},{name ="xxxx",date =15/08/2011},....]
i have one arraylist that contain list of hashmap as above . In each hashmap there is key called date. ... |
I'm basically taking a big block of chars and using each suffix as a key, each key pointing an an ArrayList that contains the index where each of these suffixes can ... |
What I have is a HashMap<String, ArrayList<String>> called examList. What I want to use it for is to save grades of each course a person is attending. So key for this ... |
I have a java Hash, the structure is like this:
HashMap<Integer, ArrayList<String>> finalMap = new HashMap<Integer, ArrayList<String>>();
The finalMap.toString() is some thing like this
{0=[a1, a2, a3, a4], 1=[b1, b2, b3], 2=[c1, c2], 3=[d1]}
I ... |
I'm doing some coursework for uni, I really should know this but I am unsure how I can update an object stored in a HashMap.
I have an abstract 'User' class that ... |
Hi, I have to create different sets of lists(arrayLists) from a ArrayList, so i am using addall, containsall like functions in my code to build new lists. But is it worth changing the base List into Hashmap, just because we can get value by Name instead of going thru loop and find the value?? If i change it to Hashmap in ... |
I think this means to write a class that works like Map but uses ArrayList internally. I was actually fool enough to do this with Vector my first week of Java because I hadn't thought to look in the API and find maps. What does a map have? Keys and values. How would you store a bunch of keys and a ... |
Why is retrieval from HashMap supposed to be faster than that from ArrayList?Here we are trying to compare HashMap.get(keyobject) and ArrayList.get(index). The complexity of HashMap retrieval is o(1)(I really do not know how;am certainly interested in knowing that) while I do not know about ArrayList. Since ArrayList is based on arrays, it has random access available to it.How anything can be ... |
import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; public class Test { public static void main(String args[]){ Map jediSaber = new HashMap(); jediSaber.put("white","Obi-wan"); jediSaber.put("blue","Anakin"); jediSaber.put("red","Lord Sidiuous"); List theList = new ArrayList(jediSaber.entrySet()); Iterator iter = theList.iterator(); while(iter.hasNext()){ Map.Entry entry = (Map.Entry) iter.next(); System.out.println("Saber Color: "+entry.getKey()); System.out.println("Jedi Name:" +entry.getValue()); } } } |
|
i would say it depends on the situation. i don't believe there is EVER a single, always correct answer. press for more info on how they are going to use this data structure... what kind of info goes in it, how will it be accessed (and how often), are duplicates allowed, etc. without that info, you can't answer the question. |
Hi I am working on implementing Joshua Bloch's Item 15 Minimize mutability, for classes that contain HashMaps and ArrayLists, for which I understand defensive copies need to be made to ensure that references to them to do not leak out through accessors. So I suppose I am looking for the most efficient idiom to do this. are these it? public class ... |
I'm not sure of the purpose here. Is the goal to memorize the arraylist and hashmap source, so that when the same question is asked, you can answer the question? I think it may be more productive to try to write it yourself -- this way, when asked again, you can reproduce it during the interview. Regardless, if you really want ... |
|
|
|
|
38. HashMap coderanch.comI've created a Hashmap like the following HashMap myMap = new HashMap(); I've added my keys and values, and I understand how to do a straight iteration through my HashMap, but how do I access only the "5th" item in the ArrayList (just as an example). So I know the 5th item in the ArrayList for each of the ... |
|
|
@fred rosenberger actually I need to create an indexing system where I need to read terms from a collection of files and store the word ,frequencies and the list of files(file ids).So, what I thought about storing the word,frequency in the hashmap and the file-ids in the arraylist where the words appear. |
manuel.leiria wrote: I still don't understand what do you mean by temporary tables? Are you talking about record sets? It's an SQL term. This is a definition I've found, * Local temporary tables are temporary tables that are available only to the session that created them. These tables are automatically destroyed at the termination of the procedure or session that created ... |
Hello, I'm new to java, but have been programming for quite some time. My question is "How do I iterate over an Arraylist of Hashmaps?". I have the following code fragment List displayParamList = new ArrayList(); pubic void setList() { // I have a global String array that contains my label and label values for (int i=0; i<2; i++) { Map ... |
|
Hi, I'm just a bit confused which to use here so was wondering could someone help me out please. My guideline is as follows. A tax office registers a wide variety of vehicles, each of which has a license number, description, horsepower, year of manufacture, engine size and owner. Some vehicles are Heavy Goods Vehicles and for these HGV's, the tachometer ... |
|
Thanks! It compiles now. All I have to do now is figure out why it is not posting the message I send from the client. It is returning a null and a walktrhough indicates it is null throughout the post method. It is a good thing I am not planning to be a programmer for a living. lol |
The fact that each client is unique and that each client can have many accounts makes sense(or is that backwards?). The Client class doesn't do anything to crucial it just has a few accessors and two methods: one for adding an accountnumber and another to make a deposit.The program as a whole seems poorly designed to me however, its more complicated ... |
if i get ID 60 in the first record, i put it into hashmap and operate on its fields, in the next loop, if iget 75, i will add it to the hash map... in the next loop if i get 60 again, it should operate on the already exixting one. Here is the code snippet i have |
|
1.HashMap has two things , loadfactor and initialCapacity - from the documents it is clear that map doubles it size once the current size id beyond the load factor. Why it should only double , why not tripple , (memory reqd may be more - but same thought can apply to doubling ) - Is there any specific reason for this. ... |
Hello I wonder how can i go over a HashMap to show it for example or to change properties in each element...etc. I have used it because i know it can be faster than an ArrayList for something, for example, to order it...etc. Insted of using an iterator after converting it into a collection, how can i order it or go ... |
Hi, I have an assignment to make a P2P program in java. Here's a scenario of what could happen: A user requests an index of all files that are shared on lan > every other client connected sends his index (all clients do this simultaneously). My question is: In which form should all clients send their index (ArrayList? HashMap?) , and ... |
|
Do you really need to have a list of items as a value? Or might it be better to have an object that encapsulates a list of items? If you insist on having a list of items (i.e., multiple values associated with one key), then either google for something like java multimap or else create an add or put method that ... |
|
a MailItem is a class that has objects to: from: message: subject if I add mapper.put("bob", mailItem1); mapper.put("jo", mailItem2); mapper.put("bob", mailItem3); how can I go through the hashmap and display all the messages that there are for each person? (mailItem has a print() method that prints out the email info. thanks all, i'm a newbie |
|
Hi, I've recently completed a project for my course and now I'm doing the write up for it. Part of my project was to load a dictionary into a data structure. I went with a HashMap because I had code from a previous project to help implement it, the dictionary was used to check possible decrypted words and return possible words ... |
private String name; private double price; private long quantity; public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public long getQuantity() { return quantity; } public void setQuantity(long quantity) { this.quantity = quantity; } public static void main(String ... |
|
|
In JDK 1.5, HashMap has a thread safe implementation, ConcurrentHashMap. As well, there is the corresponding interface ConcurrentMap. Does ArrayList have a thread safe implementation? If so, is there also a corresponding interface? I'm aware that I can use Collections.synchronizedList(new ArrayList()) but was hoping there was something more along the lines of ConcurrentHashMap and ConcurrentMap. Thanks. |
|
there will be a huge range, like a few hundret years. And there are Items, which belong to a day, week, year .... . One Item can belong to more than one point of time. At one point of time there can be more than one Item. The id of the items is til know the date. |
|
|