java 常用功能代码
4判断数组是否包含某值:
Arrays . asList (arr ) . contains (targetValue ) ; |
5 ArrayList 转String 并按指定字符分割:
ArrayList<String> androidos = new ArrayList<>();
androidos.add("android framework");
androidos.add("android souces");
androidos.add("android system");
System.out.println(String.join(" | ", androidos));
打印:android framework | android souces | android system
6 打印数组:
String[] androidos = new String[] {"android framework","android hal","android hidl","android aidl"};
System.out.print(Arrays.toString(androidos));
打印:[android framework, android hal, android hidl, android aidl]
7 最有效率的方式去遍历Map
public static void main(String[] args){
HashMap androidos = new HashMap();
androidos.put("android","androidos.net" );
Set<Map.Entry<String, String>> entrySet = androidos.entrySet();
Iterator<Map.Entry<String, String>> iter = entrySet.iterator();
while (iter.hasNext()) {
Map.Entry<String, String> entry = iter.next();
System.out.println(entry.getKey() + " " + entry.getValue());
}
}
评论