<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                Java ###String > String s1 = new String(); > String s2 = "billryan"; > int s2Len = s2.length(); > s2.substring(4, 8); // return "ryan" > StringBuilder s3 = new StringBuilder(s2.substring(4, 8)); > s3.append("bill"); > String s2New = s3.toString(); // return "ryanbill" > // convert String to char array > char[] s2Char = s2.toCharArray(); > // char at index 4 > char ch = s2.charAt(4); // return 'r' > // find index at first > int index = s2.indexOf('r'); // return 4. if not found, return -1 >StringBuffer 與 StringBuilder, 前者保證線程安全,后者不是,但單線程下效率高一些,一般使用StringBuilder * * * * * ###鏈表 ~~~ public class ListNode { public int val; public ListNode next; public ListNode(int val) { this.val = val; this.next = null; } } ~~~ * * * * * ###二叉樹 ~~~ public class TreeNode { public int val; public TreeNode left, right; public TreeNode(int val) { this.val = val; this.left = null; this.right = null; } } ~~~ * * * * * ###ArrayList ~~~ List<String> list = new ArrayList<String>(); list.add("abc"); boolean isEmpty = list.isEmpty(); int size = list.size(); boolean isExist = list.contains("abc"); int index = list.indexOf("abc"); int lastIndex = list.lastIndexOf("abc"); Object[] objectArray = list.toArray(); for(Object obj : objectArray){ System.out.println(obj); } String s = list.get(0); String old = list.set(0, "abc"); list.add(0, "ghi"); list.remove(0) ~~~ ###隊列 Queue 在 Java 中是 Interface, 一種實現是 LinkedList, LinkedList 向上轉型為 Queue, Queue 通常不能存儲 null 元素,否則與 poll() 等方法的返回值混淆。優先考慮右側方法,右側元素不存在時返回 null . 判斷非空時使用 isEmpty() 方法,繼承自 Collection ~~~ Queue<Integer> q = new LinkedList<Integer>(); int qLen = q.size(); // get queue length ~~~ | 0:0 | Throws exception | Returns special value | | --- | --- | --- | | Insert | add(e) | offer(e) | | Remove | remove() |poll()| |Examine| element()| peek()| * * * * * ###雙端隊列 Java 在1.6之后提供了 Deque 接口,既可使用 ArrayDeque ( 數組) 來實現,也可以使用 LinkedList ( 鏈表) 來實現。前者是一個數組外加首尾索引,后者是雙向鏈表。 ~~~ Deque<Integer> deque = new ArrayDeque<Integer>(); Deque<Integer> deque = new LinkedList<Integer>(); ~~~ |/||Throws exception| Special value| Throws exception| Special value| | --- | --- | |Insert| `addFirst(e)`| `offerFirst(e)`| `addLast(e)`| `offerLast(e)`| |Remove| `removeFirst()`| `pollFirst()`| `removeLast()`| `pollLast()`| |Examine |`getFirst()`| `peekFirst()` |`getLast()`| `peekLast()`| 其中 offerLast 和 Queue 中的 offer 功能相同,都是從尾部插入。 * * * * * ###棧Stack Methods > boolean isEmpty() - 判斷棧是否為空 > E peek() - 取棧頂元素,不移除 > E pop() - 移除棧頂元素并返回該元素 > E push(E item) - 向棧頂添加元素 * * * * * ###Set Set 與 Collection 具有安全一樣的接口,通常有 HashSet , TreeSet 或 LinkedHashSet 三種實現。 HashSet 基于散列函數實現,無序,查詢速度最快; TreeSet 基于紅-黑樹實現,有序。在不允許重復元素時可當做哈希表來用。 ~~~ Set<String> hash = new HashSet<String>(); hash.add("billryan"); hash.contains("billryan"); ~~~ * * * * * ###hashmap Java 的實現中 Map 是一種將對象與對象相關聯的設計。常用的實現有 HashMap 和 TreeMap ,HashMap 被用來快速訪問,而 TreeMap 則保證『 鍵』 始終有序。Map 可以返回鍵的 Set, 值的 Collection,鍵值對的 Set. ~~~ Map<String, Integer> map = new HashMap<String, Integer>(); map.put("bill", 98); map.put("ryan", 99); boolean exist = map.containsKey("ryan"); // check key exists in map int point = map.get("bill"); // get value by key int point = map.remove("bill") // remove by key, return value Set<String> set = map.keySet(); // iterate Map for (Map.Entry<String, Integer> entry : map.entrySet()) { String key = entry.getKey(); int value = entry.getValue(); // do some thing } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看