# Math and hashmaps!

Discussion in 'Plugin Development' started by Miniwarbos, Apr 15, 2014.

Not open for further replies.
1. Offline

### Miniwarbos

Hello. I want to detect a value on a player in a hashmap (sorry if i have bad terminology).
I need to detect whether a value is more than something, but less than another value.
In normal maths, it would look like this:

n<10
10<=n< 30
30<=n< 50
50<=n< 100
100<n

And here is my code:
Code:
```            public void run() {
for (Player p : Bukkit.getOnlinePlayers()) {
UUID player = p.getUniqueId();
if (map.get(player).{SOMETHING}()) {

}
}

update();
}```

How can I do this? Sorry its a really vague question but I'm new. I also need to add that the value map.get(player) is long. Thanks!

#1
2. Offline

### Asgernohns

Miniwarbos map.get(Key) returns your value so you should use it Like you would with an integer

#2
3. Offline

### Miniwarbos

Asgernohns I don't understand how i would do the math operations as well.
What would it be?

sorry for kinda asking for code, but i dont know where to start. How does 10<=n< 30 translate into that.

if (map.get(player).{SOMETHING}()) {

#3
4. Offline

### Asgernohns

#4
5. Offline

Miniwarbos
Code:java
`int value = map.get(player);if(value >= 10 && value < 30) {    //Do something}`

#5
6. Offline

### Miniwarbos

Asgernohns
That, N is the value. its algirba
Thanks!

so since map.get(player) is long, do i need to do
int value = map.get(player).intValue();

EDIT by Moderator: merged posts, please use the edit button instead of double posting.

Last edited by a moderator: Jun 7, 2016
#6
7. Offline

### Forge_User_88736224

No, just do this:
Code:java
` long value = map.get(player);if(value >=10L && value <30 L){//Do something} `

Java needs an "L" behind Longs, so it will handle it as Longs. (And all math-Operations can be used on int,long,double etc.)

8. Offline

#8