Search Results

Search found 547 results on 22 pages for 'hashmap'.

Page 2/22 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Converting javafx.util.Properties to a HashMap

    - by Mozez
    Hello, I was wondering if there is an easy way to convert the javafx.util.Properties object to a java.util.HashMap. There is the obvious way of getting each value from the Properties object and putting it in a Map. But with a large number of properties it seems like there should be a way of just getting the Map that backs javafx.util.Properties (if it is a Map). Thanks in advance for any suggestions.

    Read the article

  • java hashmap flaws ?

    - by Tiberiu Hajas
    hi there, if (agents != null) for (Iterator iter = agents.keySet().iterator(); iter .hasNext();) { // some stuffs here } I have the following piece of java code, the agents is a hashmap, wondering if anyone can figure it out why on the line with "for" statement sometimes I got NPE ? is there any flaw with hashmaps ? thanks

    Read the article

  • Java - get index of key in HashMap?

    - by llm
    In java if I am looping over the keySet() of a HashMap, how do I (inside the loop), get the numerical index of that key? Basically, as I loop through the map, I want to be able to get 0,1,2...I figure this would be cleaner than declaring an int and incrementing with each iteration. Thanks.

    Read the article

  • HashMap.containsValue - What's the point?

    - by Frederik
    I've got a HashMap and I need to fetch an item by its integer value. I notice there's a containsValue() function, but it would appear I still have to iterate through the map to find the correct index anyway. My question is; why use containsValue() if I'm required to traverse it afterwards? Also, am I missing the point completely? ;-)

    Read the article

  • Does HashMap provide a one to one correspondence?

    - by Roman
    I found the following statement: Map is an object that stores key/volume pairs. Given a key, you can find its value. Keys must be unique, but values may be duplicated. For example I have just one key/value pair (3,4). And now I put a new pair (3,5). It will remove the old pair. Right? But if I put (2,4) instead of (3,4) I will add a new pair of key/value to the HashMap. Right?

    Read the article

  • Understanding the workings of equals and hashCode in a HashMap

    - by andandandand
    I have this test code: import java.util.*; class MapEQ { public static void main(String[] args) { Map<ToDos, String> m = new HashMap<ToDos, String>(); ToDos t1 = new ToDos("Monday"); ToDos t2 = new ToDos("Monday"); ToDos t3 = new ToDos("Tuesday"); m.put(t1, "doLaundry"); m.put(t2, "payBills"); m.put(t3, "cleanAttic"); System.out.println(m.size()); } } class ToDos{ String day; ToDos(String d) { day = d; } public boolean equals(Object o) { return ((ToDos)o).day == this.day; } // public int hashCode() { return 9; } } When // public int hashCode() { return 9; } is uncommented m.size() returns 2, when it's left commented it returns three. Why?

    Read the article

  • Shortcut for adding to List in a HashMap

    - by Damo
    I often have a need to take a list of objects and group them into a Map based on a value contained in the object. Eg. take a list of Users and group by Country. My code for this usually looks like: Map<String, List<User>> usersByCountry = new HashMap<String, List<User>>(); for(User user : listOfUsers) { if(usersByCountry.containsKey(user.getCountry())) { //Add to existing list usersByCountry.get(user.getCountry()).add(user); } else { //Create new list List<User> users = new ArrayList<User>(1); users.add(user); usersByCountry.put(user.getCountry(), users); } } However I can't help thinking that this is awkward and some guru has a better approach. The closest I can see so far is the MultiMap from Google Collections. Are there any standard approaches? Thanks!

    Read the article

  • jre1.6.0_27 HashMap values() sourcecode

    - by Liu guanghua
    Today, I opened jre1.6.0_27 HashMap values() method sourcecode 389 public Set<K> keySet() 390 { 391 Set localSet = this.keySet; 392 return (this.keySet = new KeySet(null)); 393 } 394 395 public Collection<V> values() 396 { 397 Collection localCollection = this.values; 398 return (this.values = new Values(null)); 399 } I think these sourcecode are error, but I don't know why they look like this. Who can tell me why?

    Read the article

  • HashMap "WriteOnce" Implementation .. need help

    - by JavaNewbie
    import java.util.*; public class HashMapExample { public static class WriteOnceMap<K, V> extends HashMap<K, V> { public V put(K key, V value) { /* WriteOnceMap is a map that does not allow changing value for a particular key. It means that put() method should throw IllegalArgumentException if the key is already assosiated with some value in the map. Please implement this method to conform to the above description of WriteOnceMap. */ } public void putAll(Map<? extends K, ? extends V> m) { /* Pleaase implement this method to conform to the description of WriteOnceMap above. It should either (1) copy all of the mappings from the specified map to this map or (2) throw IllegalArgumentException and leave this map intact if the parameter already contains some keys from this map. */ } } }

    Read the article

  • Scala updating/creating value in a hashmap

    - by user1672739
    I don't understand this with Scala hasmaps: How do I create a value or update one if it does not exist? I am tryng to count the number of characters in a list of Strings. I've tried this code but it doesn't work : def times(chars: List[Char]): List[(Char, Int)] = { val map = new HashMap[Char, Int]() chars.foreach( (c : Char) => { map.update(c, map.get(c) + 1) }) } I understand the returning type isn't correct. But is my foreach loop wrong? Is there a prettier way to write it?

    Read the article

  • xml to hashmap - php

    - by csU
    Hi, Given an xml structure like this <gesmes:Envelope> <gesmes:subject>Reference rates</gesmes:subject> <gesmes:Sender> <gesmes:name>European Central Bank</gesmes:name> </gesmes:Sender> <Cube> <Cube time="2010-03-26"> <Cube currency="USD" rate="1.3353"/> <Cube currency="JPY" rate="124.00"/> <Cube currency="BGN" rate="1.9558"/> <Cube currency="CZK" rate="25.418"/> ... ... </Cube> </Cube> </gesmes:Envelope> how can i go about getting the values stored in to a hashmap or similar structure in php? Have been trying to do this for the last few hours now but cant manage it :D It is homework so i guess no full solutuins please( tho the actual assignment is to use the web services, i am just stuck with parsing it :D ). Maybe someone could show me a brief example for a made up xml file that i could apply to mine? Thanks

    Read the article

  • PHP - advice for java HashMap alternative in php?

    - by teutara
    I know it is super noob and will be answered in no time, but I could not figure.. sorry for any inconvenience.. Here is the thing: ID colA colB Length 1 seq1 seq11 1 2 seq1 seq11 11 3 seq3 seq33 21 4 seq3 seq33 14 I have a db with this kind of a table, has more than 10M rows. I want to loop though colA first, get the relevant colB value, and check if there are any other occurrences of the same value. For example in colB (seq11) there are 2 occurrences of colA(seq1), this time I have to combine those and output the sum of the length. Similar to this: ID colA colB Length 1 seq1 seq11 12 2 seq3 seq33 35 I am a bit java guy, but because my colleague has written everything in php and this will be just an adding, i need a php solution. With java i would have used hashmap, so that I would have the colA data once and just increment the value of "Length Column".. I know it is not a proper question, but.. Thank you in advance.. $$$$$$$$$$ EDIT $$$$$$$$$$ I tried this query in order to group by occurences: SELECT COUNT(*) SeqName FROM SeqTable GROUP BY SeqName HAVING COUNT(*)>0;

    Read the article

  • More than one unique key for HashMap problem (Java)

    - by Alex Cheng
    This question is a continuation of this thread: In short: To solve my problem, I want to use Map<Set<String>, String>. However, after I sort my data entries in Excel, remove the unnecessary parameters, and the following came out: flow content ==> content content flow content ==> content depth distance flow content ==> content depth within flow content ==> content depth within distance flow content ==> content within flow content ==> content within distance I have more than one unique key for the hashmap if that is the case. How do I go around this... anyone have any idea? I was thinking of maybe Map<Set <String>, List <String>> so that I can do something like: Set <flow content>, List <'content content','content depth distance','content depth within ', ..., 'content within distance'> But because I am parsing the entries line by line I can't figure out the way how to store values of the same repeated keys (flow content) into the same list and add it to the map. Anyone have a rough logic on how can this be done in Java? Thanks in advance.

    Read the article

  • servlet ArrayList and HashMap problem witch result

    - by nonameplum
    Hi, I have that code List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); Map<String, Object> item = new HashMap<String, Object>(); data.clear(); item.clear(); int i = 0; while (i < 5){    item.put("id", i);    i++;    out.println("id: " + item.get("id"));    out.println("--------------------------");    data.add(item); } for(i=0 ; i<5 ; i++){    out.println("print data[" + i + "]" + data.get(i)); } Result of that is: id: 0 -------------------------- id: 1 -------------------------- id: 2 -------------------------- id: 3 -------------------------- id: 4 -------------------------- print data[0]{id=4} print data[1]{id=4} print data[2]{id=4} print data[3]{id=4} print data[4]{id=4} Why only last element is stored?

    Read the article

  • Does a HashMap retain the order of its elements on the next read if it is constructed as a LinkedHas

    - by javanix
    Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap is a subclass of HashMap, I can return a LinkedHashMap from this method just fine. On the next "read" action (no adding/removing/modifying of K/V pairs), would iterating over the keys of the resulting method (which returns a HashMap) go in the same order as the originating LinkedHashMap, even though the HashMap lacks the key links?

    Read the article

  • How to Create Own HashMap in Java?

    - by Taranfx
    I know about hashing algorithm and hashCode() to convert "key" into an equivalent integer (using some mathematically random expression) that is then compressed and stored into buckets. But can someone point me to an implementation or at least data structure that should be used as baseline? I haven't found it anywhere on the web.

    Read the article

  • permute data for a HashMap in Java

    - by tuxou
    hi i have a linkedhashmap and i need to permute (change the key of the values) between 2 random values example : key 1 value 123 key 2 value 456 key 3 value 789 after random permutation of 2 values key 1 value 123 key 2 value 789 key 3 value 456 so here I permuted values between key 2 and key 3 thank you; sample of the code of my map : Map map = new LinkedHashMap(); map =myMap.getLinkedHashMap(); Set key = map.keySet(); for(Iterator it = cles.iterator(); it.hasNext();) { Integer cle = it.next(); ArrayList values = (ArrayList)map.get(cle);//an arrayList of integers int i = 0; while(i < values.size()) { //i donno what to do here i++; } }

    Read the article

  • java hashmap array to double array

    - by Tweety
    Hi, I declared LinkedHashMap<String, float[]> and now I want to convert float[] values into double[][]. I am using following code. LinkedHashMap<String, float[]> fData; double data[][] = null; Iterator<String> iter = fData.keySet().iterator(); int i = 0; while (iter.hasNext()) { faName = iter.next(); tValue = fData.get(faName); //data = new double[fData.size()][tValue.length]; for (int j = 0; j < tValue.length; j++) { data[i][j] = tValue[j]; } i++; } When I try to print data System.out.println(Arrays.deepToString(data)); it doesn't show the data :( I tried to debug my code and i figured out that I have to initialize data outside the while loop but then I don't know the array dimensions :( How to solve it? Thanks

    Read the article

  • how to specify which child class this object belong to after retrieving from a hashmap?

    - by chandra wibowo
    hi everyone, i have a parent class called Course, and two child class PostgradCourse and UndergradCourse. i have a hashmap HashMap courses; i store all the postgradCourse and undergradCourse objects in the hashmap. i want to retrieve an undergradCourse object from the hashmap using the key. Course course = courses.get(courseCode); then i want to call a method in the UndergradCourse class, setUnits() method course.setUnits(); but the compiler say cannot find symbol- method setUnit() im pretty sure the problem is the compiler is looking for a method setUnit() in the Course class instead of UndergradCourse class i did this but its not working UndergradCourse course = courses.get(courseCode); results in incompatible type so how can i retrieve undergradCourse object from the hashmap as an undergradCourse object instead of course object? so then i can call a method inside the child class thanks in advance

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >