Last active
December 16, 2015 10:08
-
-
Save yuki2006/d1c35f12517380c29529 to your computer and use it in GitHub Desktop.
Goで、mapをrangeでイテレーションすると、取り出す順番は実行ごとに異なる罠 ref: http://qiita.com/yuki2006/items/5a43644e278c0777ca52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hoge = {175: True, 119: True, 450: True} | |
for k in hoge: | |
print k, | |
print "" | |
for k in hoge: | |
print k, | |
print "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 175 450 | |
119 175 450 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
450 119 175 | |
450 119 175 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
map[175:true 119:true 450:true] | |
175 119 450 | |
175 119 450 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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