Results 1 to 7 of 7
Thread: HashMap + make a sum of it.
- 07-01-2011, 05:56 PM #1
HashMap + make a sum of it.
Hi,
I am finishing up a program becose I am going on vacation next week. However there is still one thing I can't get to work. Even though I already asked help here. But that topic is already 'old' now. So here we go again.
I have a HashMap, and now I got a for loop to look up the string (AFVDSQ) in HashMap. Now these 'numbers' respresent a value. And I would like to get the A * F * V * D * S * Q. But i don't know how to do that. And all my attemps fail...
peptide = string with the letters.Java Code:for (int i = 0; i < peptide.length(); i++) { String ss = peptide.substring(i, i +1); System.out.println(y.get(ss)); }Last edited by Lund01; 07-01-2011 at 06:40 PM.
- 07-01-2011, 06:12 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,607
- Rep Power
- 5
What does the Map store (it helps to define it at least someone in your posted code)?I have a HashMap, and now I got a for loop to look up the string (AFVDSQ) in HashMap.
What numbers and what value? Do you mean the character integer value? The hashcode? A defined value in a Map? I recommend you explain your problem in much more detail.Now these 'numbers' respresent a value
- 07-01-2011, 06:37 PM #3
I have a file and in there there are certain Strings.
Like: AVV or AQWRTESAVGFS.
Now I have created a Hashmap, below is a part of it.
And in this 'for' loop it looks at the string and takes out the number from Hashmap.Java Code:Map<String, String> y = new HashMap<String, String>(); y.put("A", "71.0788"); y.put("R", "156.1875");
Like an A represents the value: 71.0788.
What I would like is that the string (example) ARR, becomes: 71.0788 * 156.1875 * 156.1875 = ......(answer I need)
- 07-01-2011, 06:49 PM #4
Get the value String for each letter from the HashMap, use a parse method (See Double) to convert the String to a number and multiply those numbers to get the product you need.
Is that at String: "71.0788 * 156.1875 * 156.1875"becomes: 71.0788 * 156.1875 * 156.1875
or does it represent a product of the three numbers?
- 07-01-2011, 07:40 PM #5
This is the String we have: ARR
This is what I still need to add: 71.0788 * 156.1875 * 156.1875 = ......(end product I need)
These strings can be 3 letters long or 25.
There is not a solid length.
Also with this code I can look them up:
But I still don't get how I should each letter to * with the next.Java Code:for (int i = 0; i < peptide.length(); i++) { String ss = peptide.substring(i, i +1); System.out.println(y.get(ss)); }
- 07-01-2011, 07:50 PM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,607
- Rep Power
- 5
Define a variable before the loop equal to a value (say 1 for multiplication, 0 for addition), and through each iteration use Norm's advice to get the value from the map, parse it to double, then perform the math operation on the value defined prior to the loop.
- 07-01-2011, 07:54 PM #7
Similar Threads
-
How to create a new HashMap from a HashMap entries of other methods
By pandeyalok in forum Advanced JavaReplies: 7Last Post: 12-08-2009, 07:17 PM -
Hashmap - get key according to value
By gtriant in forum New To JavaReplies: 1Last Post: 12-15-2008, 02:29 PM -
hashmap
By tOpach in forum New To JavaReplies: 2Last Post: 09-24-2008, 12:55 PM -
How to make a hashmap to allow duplicate values?
By Preethi in forum New To JavaReplies: 0Last Post: 02-08-2008, 12:35 PM -
Hashmap
By dirtycash in forum New To JavaReplies: 5Last Post: 12-03-2007, 02:58 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks