<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 - 在`LinkedList`中搜索元素 > 原文: [https://beginnersbook.com/2014/07/java-search-elements-in-linkedlist-example/](https://beginnersbook.com/2014/07/java-search-elements-in-linkedlist-example/) 在本教程中,我們將學習如何搜索[`LinkedList`](https://beginnersbook.com/2013/12/linkedlist-in-java-with-example/) 中的元素。我們將使用以下兩種方法來搜索元素。 `public int indexOf(Object o)`:返回此列表中第一次出現的指定元素的索引,如果此列表不包含該元素,則返回-1。 `public int lastIndexOf(Object o)`:返回此列表中指定元素最后一次出現的索引,如果此列表不包含該元素,則返回-1。 #### 示例 這里我們有一個`String`元素的`LinkedList`,我們正在使用`LinkedList`類的`indexOf()`和`lastIndexOf()`方法搜索一個字符串。 ```java import java.util.LinkedList; public class SearchInLinkedList { public static void main(String[] args) { // Step1: Create a LinkedList LinkedList<String> linkedlist = new LinkedList<String>(); // Step2: Add elements to LinkedList linkedlist.add("Tim"); linkedlist.add("Rock"); linkedlist.add("Hulk"); linkedlist.add("Rock"); linkedlist.add("James"); linkedlist.add("Rock"); //Searching first occurrence of element int firstIndex = linkedlist.indexOf("Rock"); System.out.println("First Occurrence: " + firstIndex); //Searching last occurrence of element int lastIndex = linkedlist.lastIndexOf("Rock"); System.out.println("Last Occurrence: " + lastIndex); } } ``` **輸出:** ```java First Occurrence: 1 Last Occurrence: 5 ``` **參考:** [`LinkedList` JavaDoc](https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html)
                  <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>

                              哎呀哎呀视频在线观看