Open xiedaxia1hao opened 3 years ago
Map<Integer, Integer> map = new HashMap<>();
// Iterate by Entry
for(Map.Entry<Integer, Integer> entry : map.entrySet()) {
int key = entry.getKey();
int value = entry.getValue();
// do your stuff
}
// Iterate by Key Set
for(Integer key : map.keySet()) {
int random = key + map.get(key);
// do your stuff
}
// Iterate by Value Set
for(Integer value : map.values()) {
int random = value + 100;
// do your stuff
}
String Split by Space
// the first \ is used to escape the second \
// \s represents a whitespace character including [ \t\n\x0B\f\r].
// + handles strings with multiple spaces
myString.split("\\s+")
Double.MIN_VALUE
is actually a positive number, so we have to use -Double.MAX_VALUE
or Double.NEGATIVE_INFINITY
at the beginning if we want to keep a double value max as the answer.StringBuilder sb = new StringBuilder();
sb.append("a"); // append an element to the end
sb.deleteCharAt(sb.length()-1); // delete the last character in the StringBuilder
sb.length()
而不是 sb.size()
or sb.length
!!!
Random Java Language Syntax and so on.