FAQ Database Discussion Community


How do I create a dictionary-like android app using HashMap for words and their respective meanings?

android,dictionary,android-edittext,hashmap,android-textview
I'm trying to create an app that works like a dictionary (using HashMap), where a user types in a word (jargon) in the textEdit and if that word matches any of the words in HashMap, will display my predefined meaning of the word in a textView when user hits enter....

Adding objects to hashmap as keys which only equals method implemented [duplicate]

java,hashmap
This question already has an answer here: Why do I need to override the equals and hashCode methods in Java? 20 answers I have the below class which only equals is overridden, class S { String txt = null; S(String i) { txt = i; } public boolean equals(Object...

Why my HashMap puts an element in position 6 instead of the next empty position?

java,hashmap,order
I'm running the following code in a method, but at the time of return the key and value <"dataInicio">,<"orange"> are at position six of the map instead of position one like it should've. What could be doing this? I'm creating this map to sends as parameter to a Jasper report...

Nested Hashmaps overwriting other keys

java,hashmap,nested
I have a problem where when I want to change a value in a nested HashMap, the other HashMaps are being overwritten. for example I have a key name Alligator, which stores a HashMap that contains the keys Weight and Size. I want to be able to change the value...

How can I foreach a hashmap?

android,loops,hashmap
I have a hashmap with the values : 1 - 18; 1 - 19; 1 - 20; 3 - 21; 3 - 22; 8 - 23; 8 -24; 8 - 25; 11 - 26; And I gotta loop it and check whether the key is equal the specific value, which...

How to print value of a hash map according to increasing/decreasing order of key in c++? [on hold]

c++,hash,hashmap
If we have a map, map <int,int> m; and following key value pair (-2,3) , (-14,8) , (4,8), (6,12) , (3,76) Now if we want to print value in increasing order of keys,then how to print ? o/p 8 3 76 8 12...

How to fill HashMap object only once for program?

java,static,hashmap,instantiation
Given the following portion of my wider program: public class AnimalNames { private static String[] animalNames = {dog, cat, horse, cow, donkey, elephant}; private static String[] animalNameAbbreviations = {d, c, h, co, d, e}; public static HashMap<String, String> getAnimalNameTranslations() { HashMap<String, String> animalNameTranslations = new HashMap<String, String>(); for (int i...

HashMap or TreeMap for Map specifically sized 1

java,hashmap,treemap
I need a Map sized 1 and began to wonder what would be best, a TreeMap or a HashMap? My thought is that TreeMap would be better, as initialising and adding a value to a HashMap will cause it to create a table of 15 entries, whereas I believe TreeMapis...

Passing HashMap using intent returns null, why?

java,android,android-intent,hashmap
I'm trying to pass a hashmap from one activity to another using intent. I already found a solution which should work. I implemented Serializable in class Player. private HashMap<Integer, Player> players = new HashMap<Integer, Player>(); players.put(1, new Player("name")); Intent intent = new Intent(this, GameActivity.class); intent.putExtra("players", players); startActivity(intent); But when I...

Printing a HashMap that contains of String and List of Objects

java,hashmap
How can I print a HashMap that containts of String and List of Objects? HashMap<String, List<Object>> Map = new HashMap<String, List<Object>>(); Each object has a name and a key value so I need to get something like: StringFirst = [ firstObject 15, second object 31, thirdobject 16] StringSecond = [...

How do I set this map value to null in JSTL?

null,hashmap,jstl
In JSTL, I have HashMap as a page variable. The HashMap maps Strings to more complex Objects. I would like to set a value to null. So I'm trying value: ${myMap[myId]} <c:set target="myMap" property="${myId}" value="${null}" /> I have verified taht the "value:" statement does print something out, however, I get...

Using SORT command to get HASH fields from a sorted set in Redis

sorting,redis,hashmap,sortedset
For example, in redis-cli I've tried to create a sorted set like this: zadd sortedset 1 1 2 2 3 3 And I've created a hash like this: hset data 1 hello hset data 2 goodbye hset data 3 sir My goal is storing identifiers in sorted sets and get...

Getting a “java.lang.NullPointerException” while working whith Maps

java,dictionary,nullpointerexception,hashmap
I am trying to write a simple Diet program using maps with this code. But I keep getting NPE which keeps interrupting the process at random. What is wrong with my code? Why is that that I keep getting this error and how do I fix it? class Diet {...

how does hashmap ensure that each hash value is assigned a unique index in the hash table

java,collections,hashmap
I want to understand how hash() and indexOf() methods of HashMap assign a unique index in hash table to a hashmap. In other words, why it is not possible for multiple hash values to be mapped to the same index.

operation on 2 dimensional hash map C++

c++,hashmap
I am currently working on a coding question: Given an array of strings, return all groups of strings that are anagrams. For example, Given: {asch, scah, bva, vba, soa} return { {asch, scah}, {bva, vba}, {soa}} To solve this question less than O(n^2) time, we should firstly sort each word,...

How to get HashMap labels based on selected List

java,arraylist,hashmap
I need your assistant in getting the labels from a HashMap based on the items which are available in my ArrayList. The String ArrayList has the values ["CE1","CE2"] and its initialization in the bean is: private List<String> selectedCertificates = new ArrayList<String>(); Currently, it has two values. The HashMap code is:...

Hashmap single key holding a class. count the key and retrieve counter

java,class,hashmap,file-manipulation
I am working on a database self project. I have an input file got from: http://ir.dcs.gla.ac.uk/resources/test_collections/cran/ After processing into 1400 separate file, each named 00001.txt,... 01400.txt...) and after applying Stemming on them, I will store them separately in a specific folder lets call it StemmedFolder with the following format: in...

Adding to a Hashset inside a Hashmap

java,hashmap,hashset
I'm trying to add an object to a Hashset within a Hashmap. Here gamesAndTeams is a Hashmap, and it contains a Hashset. I've looked over some tutorials over the web but what I'm trying isn't working. Am I doing something wrong? Match newmatch = new Match(dateOfGame, stad, guestTeam, hostTeam, hostGoals,...

JSON Array to ImageView in GridView

android,arrays,json,arraylist,hashmap
Im having some problems with using a json array to populate an imageview using picasso within a gridview. I think i have most of it down but have however run into a but of a problem my plan is to a) collect the json array b) convert to a hashmap...

How can i store the frequency of the tags in any website page in Hashmap?

java,html,hashmap,jsoup
I am using a paired Hashmap in which i am storing the tags and its frequency but i am confused that how can i store the frequency in a variable. Code is as follows : package z; import java.awt.List; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import org.jsoup.Jsoup; import...

How to set image URI in HashMap

java,android,image,hashmap,uri
I am building a listview and i get the URI of an image wich i want to a HashMap using map.put. The functions to get the URI works fine i can set an image View using setImageURI(uri). What value should i use in the map.put("flag", value); The following code is...

Typecasting the return type of iterator.next() method to Character class

java,hashmap
I am trying to display the contents of the following HashMap : HashMap<Character,Integer> hm = new HashMap<Character,Integer>(); I have used the following method to print out the contents : Set hmset = hm.entrySet(); Iterator iterator = hmset.iterator(); while(iterator.hasNext()) { Character key = new Character(iterator.next()); System.out.println("key : "+key+"value : "+(Integer)hm.get(key)); }...

Will the hashmap.get method iterate over all object values itself? [closed]

java,object,hashmap
I've Googled this but couldn't find a satisfying answer. Right now, I got an object containing several values like this (that are taken from a database): public class Student { private String name; private String vorname; private int matrikelnummer; private String studiengang; private int author_id; private int grp; public Student(int...

Hashmap in UML diagram?

hashmap,uml,class-diagram
I want to write a class diagram for a class that contains a hashmap. Normally, I would do this: But my Map looks like this: private Map<Beacon, String> beaconRoute; The key is a custom class. How can I describe it in an UML diagram?...

Accessing the values of map from its key using pointer to map

c++,pointers,hashmap,dynamic-arrays,unordered-map
I want to dynamically allocate an array of pointers to an unordered_map in C++. The std::unordered map has been typedef as 'dictionary'. dict_array= ( dictionary **) calloc(input_size, sizeof(dictionary*)); Now I want to access the individual hashmaps, and for each individual hashmap (mydict), I want to access the values using some...

Java HashMap, hashCode() equals() - how to be consistent with multiple keys? [duplicate]

java,hash,hashmap,key
This question already has an answer here: What issues should be considered when overriding equals and hashCode in Java? 12 answers I have an ID class. It refers to identification for a unique person. There are two forms of ID. Username and user number. If either username matches or...

Find duplicate values in input

java,hashmap,duplicates,hashset
I have an input like: Apple: 0 1 Apple: 4 5 Pear: 0 10 Pear: 11 13 Apple: 5 10 Apple: 2 4 And I'm looking for rows, where the fruits are the same and the first value equals to another row's second vale. So I'm looking for rows like:...

Using a HashMap and an ArrayList to store variable names and values. How to use for creating new objects?

java,object,hashmap
I have a HashMap that stores the name of a object variable and the values that need to be used by the object. The object creation will be: Room [key] = new Room([value1]); Below is the HashMap: public static Map<String, List<String>> makeRoom(String[] room){ map = new HashMap<String, List<String>>(); int roomNumber...

How to sort the string on the basis of the frequency which is a part of a string? [duplicate]

java,string,sorting,hashmap
This question already has an answer here: How to sort objects in java? [duplicate] 3 answers I have a single string variable 'v1' of the form(every line is split using "\r\n"): a, 2.0, 2.0, 3.0 b, 1.0, 3.0, 6.8 c, 4.0, 2.8, 5.4 The output should be a single...

Java- HashMap.get returns null when it shouldn't

java,android,null,hashmap
I am using a HashMap to link some strings to integers, which are then used to index a list. The strings I am using in .get() are passed to a method, from an android spinner, and are definitely correct as I outputted them to the log, and they match those...

Check if keys in a hashmap are all in an array

ruby,hashmap
Say I have the array a = ["a","b"] And the hashmap {"hello" => "world", "a" => "d"} That would return false because "hello" is not in the array 'a'. The hashmap: {"a" => "hello", "a" => "world"} is fine. Is there a way to do this without manually doing all...

How to give different array list for each key when implementing HashMap>

java,dictionary,arraylist,hashmap,multimap
I want to have a different array list for each key when I use HashMap>. I would like to store the sentence id as a key and words of the sentence in array list. To do that I did the following: //I used the multimap for this task and it...

Can't retrieve from double HashMap

java,arrays,matrix,hashmap
I'm trying to make a 16 by 16 by 16 containing a value for each point. Each point is a 16 bit integer(short). I keep getting this error: Exception in thread "main" java.lang.NullPointerException at Chunk.getBlock(Chunk.java:42) at Foo.main(ChunkTest.java:12) Heres my code: import java.util.HashMap; public class Chunk { private HashMap<Byte, HashMap<Byte, Short>>...

Creating objects with data from file

java,file,io,hashmap
I’ve got a text file with data for my application and I want to create objects with that data. Every line in the text file is one object in format: <name> <posX> <posY> <posY> <velX> <velY> <velZ> <mass> <radius>. line is a String with one line from that file. To...

Reading a text file to a HashMap in Java

java,hashmap
I have a text file in the following format: Student1 Marks Student2 Marks The first column is the key. This is what I have tried so far Scanner scanner = new Scanner(new FileReader("marks.txt")); HashMap<String,Integer> map = new HashMap<String,Integer>(); while (scanner.hasNextLine()) { String[] columns = scanner.nextLine().split("\t"); map.put(columns[0],columns[1]); } System.out.println(map); } ...

How can I optimize this HashMap with 42,000 keys

java,arrays,hashmap
I have a csv file with 42,000 lines in the following pattern 03055,Milford,NH 03057,Mont Vernon,NH 03060,Nashua,NH I tried to store the data in a HashMap using the zipcode as a key, like while ((line = stream_in.readLine())!=null) { LocationBean temp_location_bean = new LocationBean(); String line_trimmed = line.trim(); String[] line_chunked = line_trimmed.split(",",4);...

How to omit creating static Map for data caching?

java,caching,static,hashmap
I want to know if it is possible to omit creating cache with static Map instance. Here is snippet of my class: public class XpathEvaluator { private DocumentBuilder builder; private XPath path; private Document document; private static Map<String, List<String>> cachedXpaths = new HashMap<>(); private XpathEvaluator() throws ParserConfigurationException { DocumentBuilderFactory factory...

creating nested Json from array list multi map in java

java,json,arraylist,hashmap
I have an array list multi map - ArrayListMultimap<String, String> fcmbuildProperties = ArrayListMultimap.create(); ArrayListMultimap<String, String> scm = ArrayListMultimap.create(); //HashMap<String, String> fcmbuildProperties= new HashMap<String, String>(); fcmbuildProperties.put("name", buildName); fcmbuildProperties.put("timestamp", buildTimeStamp); fcmbuildProperties.put("groupId", groupID); fcmbuildProperties.put("artifactId", artifactID); fcmbuildProperties.put("version", version);...

Mongo: get hashmap in aggregate

javascript,mongodb,hashmap,aggregate,mongodb-query
I have collection db.problems. Each document contains nested area and category objects. Document's example: { _id: 1, text: 'Hello', area: {_id: 23, title: 'Area 61'}, category: {_id: 12, title: 'Just a category'} } I'm trying to count problems in every area by category and get something like this: [ {...

Same Code is producing different outputs for Java 7 & 8

java,sorting,hashmap,comparator
On Giving Input as 91912323 it gives output as 33221199 for Java 8 while in Java 7 the output is 11223399. The problem statement is also provided for your reference. Any help would be appreciated. A string consists of digits from 1-9 will be passed as input. The program must...

How to map two arrays to one HashMap in Java?

java,arrays,arraylist,hashmap
I have two String arrays. One having short name. // days short name String[] shortNames = {"SUN", "MON", "...", "SAT"}; The other having long name. // days long name String[] longNames = {"SUNDAY", "MONDAY", "....", "SATURDAY"}; Both having same number of elements. How can I map short name as KEY...

Why are these values retrieved with keys in HashMap? [duplicate]

java,hashmap
This question already has an answer here: Are mutable hashmap keys a dangerous practice? 6 answers I am struggling with the reason why I am getting the second line of outputs as "Line2: null" when running the following piece of code on HashMap: import java.util.*; class Dog { public...

Finding Mode of a Data Set using HashMap and ArrayList. Can't figure it out [duplicate]

java,debugging,arraylist,hashmap,mode
This question already has an answer here: What's the simplest way to print a Java array? 17 answers So I'm trying to make a set of methods that find the mode of a set of ints given to it (in the form of an array), and return an array...

Complex Hashmap ArrayList Generator

java,arraylist,hashmap,indexof
Here's some code: ArrayList<String> List = new ArrayList<>(); Map<String, List<String> > map = new HashMap<String, List<String>>(); List.add("stringA"); List.add("stringB"); List.add("stringC"); for(int i = 0; i<List.size();i++){ String key = List.get(i); List<String> value = new ArrayList<String>(); map.put(key, value); } This code takes whatever is in the ArrayList, loops through it, adds it to...

return hashmap changes pointers instead of returning values

java,hashmap
While I have been programming for years, I am new to Java. I have run into a problem with HashMaps that I'm not sure how to resolve. I thought I searched this site pretty well, but I must not be using the right terms, as I don't think I am...

HashMap returning null values

java,hashmap
Hey guys this is my code In the loop when i put mapTable.get("NN"). It is giving the correct value but in the print statement outside the loop it is giving null. pls help. Map<String,String> mapTable=new HashMap<String,String>(); while((line2=br1.readLine())!=null) { if((!line2.trim().isEmpty())&&Character.isDigit(line2.charAt(0))) { String[] tmp=line2.split("\t"); mapTable.put(tmp[1].trim(),tmp[2].trim()); System.out.println("MAP-----"+tmp[1]+ " -> "+tmp[2]+" ex "+mapTable.get("NN")); }...

Load Dictionary Text File Into Java

java,dictionary,data-structures,hashmap
I need to load a text file of information into Java. The Text file looks like this "reproduce": { "VB": 7 }, "drill": { "VB": 8, "NN": 16 }, "subgross": { "JJ": 2 }, "campsites": { "NNS-HL": 1, "NNS": 1 }, "streamed": { "VBN": 1, "VBD": 2 } It is...

map of map of structs and “assignment to entry in nil map”

go,hashmap
Here's an example where I get assignment to entry in nil map every time: https://play.golang.org/p/LudJs0rVbs To demonstrate what I'm trying to do, here's a naive version that causes 2 lookups to the database (you'll have to use your imagination on line 11): https://play.golang.org/p/YZNFeMHyMs Basically, I'm trying to do this: things...

dynamically populate hashmap with human language dictionary for text analysis

java,dictionary,hashmap,nlp
I'm writing a software project to take as input a text in human language and determine what language it's written in. My idea is that I'm going to store dictionaries in hashmaps, with the word as a key and a bool as a value. If the document has that word...

how to print this map ( java) Map > graph = new HashMap>();[solved] [duplicate]

java,list,dictionary,hashmap
This question already has an answer here: How do I print my Java object without getting “[email protected]”? 4 answers Map <String ,List<Edge>> graph = new HashMap<String, List<Edge>>(); this is the map i filled it with nodes(String) and edges(neighbor(String),weight(int)) ı can print the keys but ı couldnt reach the neighbor...

Remove all objects from list that does not exist in another list

java,arraylist,collections,hashmap,java-collections-api
I have two list List<Map<String,Object>> list1 = new ArrayList<Map<String,Object>>(); List<Map<String,Object>> list2 = new ArrayList<Map<String,Object>>(); HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put("1", new Long(1L)); HashMap<String, Object> hm2 = new HashMap<String, Object>(); hm2.put("2", new Long(2L)); HashMap<String, Object> hm3 = new HashMap<String, Object>(); hm3.put("3", new Long(3L)); HashMap<String, Object> hm4 = new...

Hashmap Adapter doesn't like the Textview cast for displaying

android,hashmap,android-arrayadapter
So I was making a ArrayAdapter which takes a HashMap(String, Card) where Card is just a custom class of two strings basically to display information on a ListView later So I rewrite the getView method like: public View getView(int position, View changeView, ViewGroup parent) { final View result; if(changeView ==...

Error When Adding HashMap to ArrayList

android,arraylist,hashmap
The goal of the app is: Get all rooms ( type, id , ratein one night promotion...etc) of the hotel by the link here. Add them to a list view Sort the list view by rooms's type I'm getting the error when I try to add the HashMap to the...

Update value in mutable HashMap

hashmap,rust
Here is what I am trying to do: use std::collections::HashMap; fn main() { let mut my_map = HashMap::new(); my_map.insert("a", 1); my_map.insert("b", 3); my_map["a"] += 10; // my expected outputs is my_map becomes {"b": 3, "a": 11} } Raises the following error: post_test_6.rs:11:5: 11:22 error: cannot assign to immutable indexed content...

How do HashMap.values() and HashMap.keySet() return values and keys?

java,hashmap
The source code of HashMap.values() is shown as follows public Collection<V> values() { Collection<V> vs = values; return (vs != null ? vs : (values = new Values())); } As you can see, when the values() method first called, it just returns a Values object. The Values object is a...

How to use generics in a method declaration

java,generics,hashmap
I have a controller which initializes HashMap(for example). How I can use the k and v in the Generic Declaration of the HashMap public static void testMyMethods(Class k, Class v) { // Tried the below code, but it is having compile time issues HashMap < k.getClass(), v.getClass() > hm =...

Java HashMap - Is it necessary to use .put() for each set? [duplicate]

java,hashmap
This question already has an answer here: How to directly initialize a HashMap (in a literal way)? [duplicate] 6 answers Imagine the following scenario. You have a set of values which are already accessible and known. You have to put them into a HashMap for reasons. Code example: String...

java - NullPointerException in Graph

java,nullpointerexception,hashmap
I was trying to implement an undirected graph using a HashMap of ArrayList to represent the adjacency list. However, I got the null pointer exception error when I initialize the adjacency list, in which I was unable to identify the null pointer. Sorry for the stupid question but I'd appreciate...

How do I use a HashMap from another class or function?

java,class,hashmap
Here is a working code example. Thanks to @markspace for providing me with it. The code here makes a hashmap and inserts values in it. public class RpgPersonExample { public static void main( String[] args ) { Map<String, RpgPerson> team = new HashMap<>(); team.put( "Sgt. Mayhem", new RpgPerson( 100, 10,...

how to save hashmap of objects to shared preferences

android,hashmap,sharedpreferences
I have a hashmap of objects.I want to save that to shared preferences and get it. How can I do this?

retrieve Hashmap Elements by index based

java,indexing,hashmap
Map pins = new HashMap(); pins.put("t1","test1"); pins.put("t2","test2"); pins.put("t3","test3"); pins.put("t4","test4"); Here is my code,i store key and values in HashMap. And i want to retrieve key and value by index value just like array. Retrieve value by key using iterator working. But i want index based can any body help me...

Hashmap that keeps original key/value when duplicate key entered

java,hashmap,key-value,duplicate-entry
Is it possible for a Hashmap to keep its original key/value pair when a duplicate key is entered? For example, let's say I have something like this: Map<String, String> map = new HashMap<String, String>(); map.put("username","password1"); map.put("username","password2"); I want the original key/value pair - username, password1 to be kept and not...

HashMap Object array data gets replaced

java,object,hashmap
I am adding data into HashMap where node is an object with variables index and successor. private static HashMap <Integer, node> peerList = new HashMap<Integer, node>(); public void generateFingerTable (int node_position) { chordSize = chord.initChordSize; chord chord = new chord(); //create new node and add to map node newPeer =...

Expiration of HashMap in Redis python?

python,database,python-2.7,redis,hashmap
I want to store the following hash map in redis: "data": { "name": "XYZ", "age": 22, "address": "a-z" } I want this whole hash map (with the given key) to expire in time, let's say 72 hours. How do I use ttl/expire function in python?...

HashMap vs. ArrayList insertion performance confusion

java,arraylist,hashmap,time-complexity,asymptotic-complexity
From my understanding a hashmap insertion is O(1) and for an arraylist the insertion is O(n) since for the hashmap the hashfunction computes the hashcode and index and inserts the entry and an array list does a comparison every time it enters a new element.

How to remove all the mappings of a particular object in java hashmap?

java,hashmap
I have a many-to-one mapping in java hashmap. I iterate through all the values by using java.util.HashMap.values(). Now if I want to delete a particular value and all the corresponding keys, then what should I do? Will just using java.util.HashMap.remove(Object key) with one of the keys suffice?...

Search for key in Map when the values are in ArrayList [closed]

java,arraylist,collections,hashmap,key-value
I am new to the collections in Java , I have a HashMap<String, List<String>>. I want to search for a key from the Map when a value is given. The map stores the data of a state as key and its cities as the list. So it is assumed that...

Reference to row in JTable

java,hashmap,jtable
JTable stores rows which can be added, deleted, shuffled, dynamically. In my implementation row represent a Download, whose progress can be dynamically updated, by passing value of one of the unique attribute called id. But how do I map id with actual row? Iterating over the column is not efficient...

Iterating through a array of hashes in a hash that has multiple indexes

arrays,perl,loops,hash,hashmap
I am currently writing a perl script that has a few hashes that containing: (Do not take this as lines of codes, it's just to show/explain) $details{tester_name} is "UFLEX-06" $details{op_sys} is "Windows" $details{igxl_vn} is "8.00.01_uflx (P7)" $details{slot} -> see below for details $details{board_name} -> see below for details Now in...

How to retrieve previous values from HashMap?

java,hashmap
I have the following code where I'm reading from a text file. The text file i as follows: 111 Laptop 500 10 222 Mobile 120 8 333 Notebook 4 100 444 Chocolates 3 50 555 Guitar 199 5 666 LenovoLaptop 470 10 777 HPLaptop 450 10 888 SonyVAIO 525 5...

Hash Map entries collision

java,eclipse,dictionary,hash,hashmap
I am trying this code snippet Map headers=new HashMap(); headers.put("X-Capillary-Relay","abcd"); headers.put("Message-ID","abcd"); Now when I do a get for either of the keys its working fine. However I am seeing a strange phenomenon on the Eclipse debugger. When I debug and go inside the Variables and check inside the table entry...

static method returns empty hashmap

java,hashmap
I have some code where there are 2 classes, A and and util class with static methods B. The class B has a static method called by A. This static method returns a hashmap (); Although the map is properly built by the static method in clas B, the map...

How to compare the structure and type of two hash tables, not the values

ruby,hash,hashmap
I am trying to compare the structure of two hash tables. I want to see if any given hash table is a subset of a master table. Example of valid sub-table: master_table = {a: String, b: Object, c: { nested_a: Integer, nested_b: Integer} } my_table = {a: 'cool value', c:...

Map filled with file names and set as request attribute by servlet appears empty in JSP

jsp,servlets,hashmap,file-handling
I'm creating a blogging system for a project (academic). I have a problem where I need to pass a map (LinkedHashMap) to a jsp file. But browser shows Nothing. Here's my code: public void doService (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String path = "localhost:8080/YouBlogger/Posts/"; File dir =...

How a hash map load factor is determined during initialisation?

java,hashmap
When a hash map is initialised, 16 slots are created. All the them are empty in the beginning. Load factor is the ratio of number of elements occupied to the size of the hash map. So the default or initial load factor must be 0 right? But while referring the...

Why Linkedlist in hashmap?Why not other implementation of List?

java,arrays,linked-list,hashmap
As HashMap uses LinkedList when two different keys produces a same hashCode.But I was wondering what makes LinkedList a better candidate here over other implementation of List.Why not ArrayList because ArrayList uses Array internally and arrays have a faster iteration compared to a LinkedList.

Group JTree Nodes Using HashMap

java,hashmap,jtree
I'm trying to build a JTree using a HashMap, with the Values as the main category and Keys as the sub-category. Essentially it'll look like this: Movies -Marvel -The Avengers -Guardians of the Galaxy -James Bond -Casino Royale -Skyfall Right now when I try to build the tree, I get...

Cannot convert 'const bool' to 'jobject

c++,hashmap,jni
I need to add a bool to an object map, my bool is defined as a primitive, and I need to convert it to an object. How do I do that ?...

Java remove data that is duplicated

java,arraylist,hashmap
Is it possible to get all the distinct values in an arraylist or hashmap? Let's say for example I have elements on arraylist like this : 123, 123, 456, 123, 456, 000 And in HashMap : 123, test1 123, test2 456, test3 123, test4 000, test5 ...

Java list: get amount of Pairs with pairwise different Keys using lambda expressions

list,lambda,stream,hashmap
I have a list of key-value-pairs and I want to filter a list where every key parameter only occurs once. So that a list of e.g. {Pair(1,2), Pair(1,4), Pair(2,2)} becomes {Pair(1,2), Pair(2,2)}. It doesn't matter which Pair gets filtered out as I only need the size (maybe there's a different...

Getting a Expected identifier or '(' issue in Xcode 6.1

c,pointers,hashmap,xcode6,expected-exception
I'm quite new to C. I've tried other links but no dice. I'm using Xcode 6.1 and I get the following issues: Parse Issue: Expected identifier or '(' Semantic Issue: Unexpected type name 'map' Here's my code: //hashmap.h #ifndef __HashMap__hashmap__ #define __HashMap__hashmap__ void map_init(); void map_insert(uint8_t, uint8_t); uint8_t map_getVal(uint8_t); #endif...

HashMap - contains and get methods should not be used together

java,algorithm,dictionary,hash,hashmap
I got the following question from an interview. I was given a character array like this: char[] characters = {'u', 'a', 'u', 'i', 'o', 'f', 'u'}; I needed to get the distinct characters and counts of each character: u = 3 a = 1 i = 1 o = 1...

How do I update an Array nested in a Hash?

arrays,ruby,hashmap
My script has: my_hash = {'key1' => 'value1', 'key2' => ['value2', 'value3']} my_array = ["text...#{variable1}", "text...#{variable2}", "text...#{variable3}"] my_hash['key2'] = my_array I receive: []=': can't convert Hash into String (TypeError). How do I update the whole array for key2?...

What kind of hashing function/algorithm does javascript associative array use?

javascript,hashmap,associative-array
We learned there are many different hashing algorithms/functions, I'm curious which one is used by javascript (v8, if the implementation matters).

java - how to create custom hashtable iterator?

java,iterator,hashmap,hashtable,inner-classes
I am currently trying to implement a Hashtable collection--I have everything up and running but I ran into kind of a conceptual problem when I was trying to define a custom iterator for the table. I have an internal class called 'HashEntry' which are the actual objects stored in the...

How to access the keys of a Hashmap and compare them with a predetermined value?

java,hashmap,unique
I have this Hashmap: HashMap<String, Student> students = new HashMap<String, Student>(); After getting 2 String values from the user input (sNo, name) I have been able to put these into the hashmap as such: students.put(sNo, new Student(sNo, name)); My problem is, each time I run through this process I want...

Is it possible to get both Interger and String value from one HashMap method?

android,hashmap
I want to merge my two Hashmap methods. One method is for getting user ID and the other is for getting user String information. But I want to get all information from one hashmap method. Is it possible? If it is, how can I do this in my getuserdetails hashmap...

Returning value which is obtained in onPostExecute method of AsyncTask

android,android-asynctask,hashmap
So I'm calling checkbetoutcome() from another activity. My goal is to carry out the AsyncTask and return the finaloutcomes variable which is populated in the onPostExecute() method. How do I achieve this as so that I don't end up with an empty finaloutcomes variable since the AsyncTask is running in...

error in my for loop over a hashmap

java,loops,hashmap
it's my first time to deal with HashMap's and i'm trying to make a simple loop to loop over each key but the code doesn't even enter the for-loop...can anyone help me plz? for(int i=0; i< ackPkts.size()-1; i++){ System.out.println("yasmin"); if (ackPkts.get(i).getAckNo() == ackPkts.get(i-1).getAckNo()){ System.out.println("there's a retransmissionS here"); }else{ v =...

How to use Google Protobuf Map in C++?

c++,hashmap,protocol-buffers,c++14
I am attempting to use the new protobuf Map functionality in C++. The following was done on Ubuntu 14.04 with gcc 4.9.2 C++14 and protobuf 3.0.0-alpha-4: Message definition: message TestMap { map<string,uint64> map1 = 1; } Then, I tried to compile the following example program: auto test = debug::TestMap::default_instance(); auto...

How to properly implement a hash-map/do I even need one

javascript,ruby-on-rails,hashmap
I am trying to use ChartsJS to great a graph of followers over time. I already have the graph working using a less efficient method. Data: A row of dates (when each follow happened) dates = ['Mar 15', 'Mar 16', 'Mar 18', 'Mar 18'] The graph takes an array of...

JSON Representation of HashMap

java,json,hashmap
what is the Json representation of HashMap<String, String>? I have tried this way but getting bad request error. "userPreferences":{{"mobile":"yes"},{"email":"yes"}} ...

hashmap iterator when used inside synchronized method

java,multithreading,hashmap
so let's say I have a Hashmap that looks like: key : value (string 1, queue 1) (string 2, queue 2) (string 3, queue 3) I also have a synchronized method that will access this hashmap, and an iterator is created inside the method: Iterator it = hashmap.iterator(); while(it.hasNext()){ Queue...

How to make this code more performant?

performance,go,hashmap
I have this snippet of code that iterate over a map and filter some fields based on relation type, I have to run two loops and have a feeling that it is going to be slow for big maps. Is there any way I can technique/refactoring to make this code...

Convert String to HashMap

java,string,serialization,dictionary,hashmap
I have to save some info to Hard Disk then load it. To save info I do: myMap.toString --> write to filename then I read from Disk: String myFutureMap = read filename. HashMap<Integer, MyData> = convertFromString(myFutureMap) class MyData{ public int sumaTiCuadrado; public int n; public int TTotal; } how can...

Using split method to store values in HashMap

java,string,split,hashmap
I have a string in the following format : "(1,X) (3,2) (5,2) (7,2)" Basically the first element can be any positive integer, the second element is either '1' 'X' or '2'. The string can be of varying length with the minimum being one element. I want to split this string...

Java Hashmap: Get key from a given ARRAY of values

java,arrays,hashmap,key
I have a hashMap called prizeWinners. The key for each pair in the hashMap is the year a nobel prize was won. The value is the name(s) of the winners. The value is an array of Strings, because in any given prize year, there can be up to 3 winners....

Storing the map contents into another map in java

java,hashmap
I have the below java class public class DataStruc { private List<String> TradeRef; private List<String> TMS; public DataStruc(List<String> TradeRef, List<String> TMS) { setTradeRef(TradeRef); setTMS(TMS); } //setters and getters for them } I have the below map which is as shown below and into which i am explicitly creating the list...

I am trying to remove a single value from a MultiMap(org.apache.commons.collections.MultiMap) in JAVA

java,collections,graph,hashmap
I am trying to remove a single value from a MultiMap (org.apache.commons.collections.MultiMap) in Java. The issue is it contains two values. When I remove one, the other gets removed as well. class MappedValue { public MappedValue(String id , boolean touched) { identifier = id; this.touched=touched; } private String identifier; private...

Java using HashMap userinput loop

java,hashmap
I saw a student registration sample and wanted to write it using HashMap in my own way to learn more about HashMap. About the program: 1)You can add student name and student id -class Student import java.util.*; public class Student { Scanner userInput = new Scanner(System.in); public String sName(){ System.out.print("Enter...