Skip to content

Instantly share code, notes, and snippets.

@yuki2006
Last active December 16, 2015 10:08
Show Gist options
  • Save yuki2006/d1c35f12517380c29529 to your computer and use it in GitHub Desktop.
Save yuki2006/d1c35f12517380c29529 to your computer and use it in GitHub Desktop.
Goで、mapをrangeでイテレーションすると、取り出す順番は実行ごとに異なる罠 ref: http://qiita.com/yuki2006/items/5a43644e278c0777ca52
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] args) {
HashMap<Integer, Boolean> map = new HashMap<>();
map.put(175, true);
map.put(119, true);
map.put(450, true);
for (Map.Entry<Integer, Boolean> element : map.entrySet()) {
System.out.print(element.getKey());
System.out.print(" ");
}
System.out.println();
for (Map.Entry<Integer, Boolean> element : map.entrySet()) {
System.out.print(element.getKey());
System.out.print(" ");
}
System.out.println();
}
}
hoge = {175: True, 119: True, 450: True}
for k in hoge:
print k,
print ""
for k in hoge:
print k,
print ""
119 175 450
119 175 450
package main
import (
"fmt"
)
func main() {
set := map[int] bool{}
set[175] = true
set[119] = true
set[450] = true
fmt.Println(set)
//イテレーション1
for key, _ := range set {
fmt.Print(key)
fmt.Print(" ")
}
fmt.Println()
//イテレーション2
for key, _ := range set {
fmt.Print(key)
fmt.Print(" ")
}
fmt.Println()
}
450 119 175
450 119 175
map[175:true 119:true 450:true]
175 119 450
175 119 450
map[450:true 175:true 119:true]
175 119 450
119 450 175
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment