保存.md
用Map時(shí),如果沒重寫hashCode(),那么hashCode就是地址值。
Map用Entry遍歷
? ? ? ?Map<String, String> map = new HashMap<>();
? ? ? ?map.put("superman", "zzkJerry");
? ? ? ?map.put("1", "one");
? ? ? ?map.put("2", "two");
? ? ? ?map.put("3", "three");
? ? ? ?for (Map.Entry<String, String> entry : map.entrySet()) {
? ? ? ? ? ?System.out.println(entry);
? ? ? ? ? ?System.out.println(entry.getKey() + "=" + entry.getValue());
? ? ? ?}
用String_Builder反轉(zhuǎn)String
System.out.println(new StringBuilder("zzkJerry").reverse());
聲明泛型方法
//聲明泛型方法,可以實(shí)現(xiàn)任意引用類型數(shù)組指定位置元素交換。
public static <T> void method(T[] arr, int a, int b) {
? ?T temp = arr[a];
? ?arr[a] = arr[b];
? ?arr[b] = temp;
}
Iterator_Demo
? ? ? ?Collection collection = new ArrayList<String>();
? ? ? ?collection.add("qwer");
? ? ? ?collection.add("zzkJerry");
? ? ? ?collection.add("Tomcat");
? ? ? ?Iterator<String> iterator = collection.iterator();
? ? ? ?while (iterator.hasNext()) {
? ? ? ? ? ?System.out.println(iterator.next());
? ? ? ?}
Scanner_Demo
? ? ? ?Scanner scanner = new Scanner(System.in);
? ? ? ?String str = scanner.next();
? ? ? ?int i = scanner.nextInt();
? ? ? ?double d = scanner.nextDouble();
? ? ? ?scanner.close();
統(tǒng)計(jì)字符串中的每一個(gè)字符個(gè)數(shù),用到Map
? ? ? ?// 統(tǒng)計(jì)字符串中的每一個(gè)字符個(gè)數(shù)
? ? ? ?String str = "qwerqweqwq";
? ? ? ?Map<Character,Integer> map = new HashMap<>();
? ? ? ?for (int i = 0; i < str.length(); i++) {
? ? ? ? ? ?char ch = str.charAt(i); // 遍歷拿到String中的每一個(gè)字符
? ? ? ? ? ?int count = map.getOrDefault(ch,0); // 取到原來的值
? ? ? ? ? ?map.put(str.charAt(i),++count); // 累加
? ? ? ?}
? ? ? ?System.out.println(map);
Java學(xué)習(xí)筆記,這里是段落
// 這里是代碼塊
一級(jí)標(biāo)題
二級(jí)標(biāo)題
三級(jí)標(biāo)題
四級(jí)標(biāo)題
五級(jí)標(biāo)題
六級(jí)標(biāo)題
這里是段落