<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國際加速解決方案。 廣告
                # Kotlin 程序:按屬性對自定義對象的`ArrayList`進行排序 > 原文: [https://www.programiz.com/kotlin-programming/examples/sort-custom-objects-property](https://www.programiz.com/kotlin-programming/examples/sort-custom-objects-property) #### 在此程序中,您將學習按照 Kotlin 中給定屬性對自定義對象的`ArrayList`進行排序。 ## 示例:按屬性對自定義對象的`ArrayList`進行排序 ```kt import java.util.* fun main(args: Array<String>) { val list = ArrayList<CustomObject>() list.add(CustomObject("Z")) list.add(CustomObject("A")) list.add(CustomObject("B")) list.add(CustomObject("X")) list.add(CustomObject("Aa")) var sortedList = list.sortedWith(compareBy({ it.customProperty })) for (obj in sortedList) { println(obj.customProperty) } } public class CustomObject(val customProperty: String) { } ``` 運行該程序時,輸出為: ```kt A Aa B X Z ``` 在上面的程序中,我們定義了一個`CustomObject`類,它帶有`String`屬性,即`customProperty`。 在`main()`方法中,我們創建了以 5 個對象初始化的自定義對象`list`的`ArrayList`。 為了使用屬性對列表進行排序,我們使用`list`的`sortedWith()`方法。`sortedWith()`方法采用比較器`compareBy`,該比較器比較每個對象的`customProperty`并將其排序。 然后將已排序的列表存儲在變量`sortedList`中。 這里是等效的 Java 代碼: [Java 程序:通過屬性對自定義對象的`ArrayList`進行排序](/java-programming/examples/sort-custom-objects-property "Java program to sort an ArrayList of custom objects by property")。
                  <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>

                              哎呀哎呀视频在线观看