<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=KOTLIN%3A_List</id>
	<title>KOTLIN: List - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://lms.onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=KOTLIN%3A_List"/>
	<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;action=history"/>
	<updated>2026-04-20T18:12:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;diff=65901&amp;oldid=prev</id>
		<title>Unknown user: /* The get() Method */</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;diff=65901&amp;oldid=prev"/>
		<updated>2022-07-23T03:45:57Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;The get() Method&lt;/span&gt;&lt;/p&gt;
&lt;a href=&quot;https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;amp;diff=65901&amp;amp;oldid=65900&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;diff=65900&amp;oldid=prev</id>
		<title>Unknown user at 03:08, 23 July 2022</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;diff=65900&amp;oldid=prev"/>
		<updated>2022-07-23T03:08:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;amp;diff=65900&amp;amp;oldid=65802&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
	<entry>
		<id>https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;diff=65802&amp;oldid=prev</id>
		<title>Unknown user: Created page with &quot;Sumber: https://www.tutorialspoint.com/kotlin/kotlin_lists.htm    Kotlin list is an ordered collection of items. A Kotlin list can be either mutable (mutableListOf) or read-on...&quot;</title>
		<link rel="alternate" type="text/html" href="https://lms.onnocenter.or.id/wiki/index.php?title=KOTLIN:_List&amp;diff=65802&amp;oldid=prev"/>
		<updated>2022-07-18T02:37:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Sumber: https://www.tutorialspoint.com/kotlin/kotlin_lists.htm    Kotlin list is an ordered collection of items. A Kotlin list can be either mutable (mutableListOf) or read-on...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Sumber: https://www.tutorialspoint.com/kotlin/kotlin_lists.htm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kotlin list is an ordered collection of items. A Kotlin list can be either mutable (mutableListOf) or read-only (listOf). The elements of list can be accessed using indices. Kotlin mutable or immutable lists can have duplicate elements.&lt;br /&gt;
&lt;br /&gt;
Creating Kotlin Lists&lt;br /&gt;
For list creation, use the standard library functions listOf() for read-only lists and mutableListOf() for mutable lists.&lt;br /&gt;
&lt;br /&gt;
To prevent unwanted modifications, obtain read-only views of mutable lists by casting them to List.&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    println(theList)&lt;br /&gt;
    &lt;br /&gt;
    val theMutableList = mutableListOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    println(theMutableList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[one, two, three, four]&lt;br /&gt;
[one, two, three, four]&lt;br /&gt;
Loop through Kotlin Lists&lt;br /&gt;
There are various ways to loop through a Kotlin list. Lets study them one by one:&lt;br /&gt;
&lt;br /&gt;
Using toString() function&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    println(theList.toString())&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[one, two, three, four]&lt;br /&gt;
Using Iterator&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
    val itr = theList.listIterator() &lt;br /&gt;
    while (itr.hasNext()) {&lt;br /&gt;
        println(itr.next())&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
one&lt;br /&gt;
two&lt;br /&gt;
three&lt;br /&gt;
four&lt;br /&gt;
Using for loop&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
   for (i in theList.indices) {&lt;br /&gt;
      println(theList[i])&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
one&lt;br /&gt;
two&lt;br /&gt;
three&lt;br /&gt;
four&lt;br /&gt;
Using forEach&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
   theList.forEach { println(it) }&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
one&lt;br /&gt;
two&lt;br /&gt;
three&lt;br /&gt;
four&lt;br /&gt;
Note - here it works like this operator in Java.&lt;br /&gt;
Size of Kotlin List&lt;br /&gt;
We can use size property to get the total number of elements in a list:&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, null, &amp;quot;four&amp;quot;, &amp;quot;five&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
    println(&amp;quot;Size of the list &amp;quot; + theList.size)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
Size of the list 5&lt;br /&gt;
The &amp;quot;in&amp;quot; Operator&lt;br /&gt;
The in operator can be used to check the existence of an element in a list.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
   if(&amp;quot;two&amp;quot; in theList){&lt;br /&gt;
      println(true)&lt;br /&gt;
   }else{&lt;br /&gt;
      println(false)&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
true&lt;br /&gt;
The contain() Method&lt;br /&gt;
The contain() method can also be used to check the existence of an element in a list.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
   if(theList.contains(&amp;quot;two&amp;quot;)){&lt;br /&gt;
      println(true)&lt;br /&gt;
   }else{&lt;br /&gt;
      println(false)&lt;br /&gt;
   }&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
true&lt;br /&gt;
The isEmpty() Method&lt;br /&gt;
The isEmpty() method returns true if the collection is empty (contains no elements), false otherwise.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
   if(theList.isEmpty()){&lt;br /&gt;
      println(true)&lt;br /&gt;
   }else{&lt;br /&gt;
      println(false)&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
false&lt;br /&gt;
The indexOf() Method&lt;br /&gt;
The indexOf() method returns the index of the first occurrence of the specified element in the list, or -1 if the specified element is not contained in the list.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
    &lt;br /&gt;
   println(&amp;quot;Index of &amp;#039;two&amp;#039; :  &amp;quot; + theList.indexOf(&amp;quot;two&amp;quot;))&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
Index of &amp;#039;two&amp;#039; : 1&lt;br /&gt;
The get() Method&lt;br /&gt;
The get() method can be used to get the element at the specified index in the list. First element index will be zero.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
   val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
   println(&amp;quot;Element at 3rd position &amp;quot; + theList.get(2))&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
Element at 3rd position three&lt;br /&gt;
List Addition&lt;br /&gt;
We can use + operator to add two or more lists into a single list. This will add second list into first list, even duplicate elements will also be added.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
    val firstList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;)&lt;br /&gt;
    val secondList = listOf(&amp;quot;four&amp;quot;, &amp;quot;five&amp;quot;, &amp;quot;six&amp;quot;)&lt;br /&gt;
    val resultList = firstList + secondList&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[one, two, three, four, five, six]&lt;br /&gt;
List Subtraction&lt;br /&gt;
We can use - operator to subtract a list from another list. This operation will remove the common elements from the first list and will return the result.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
    val firstList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;)&lt;br /&gt;
    val secondList = listOf(&amp;quot;one&amp;quot;, &amp;quot;five&amp;quot;, &amp;quot;six&amp;quot;)&lt;br /&gt;
    val resultList = firstList - secondList&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[two, three]&lt;br /&gt;
Slicing a List&lt;br /&gt;
We can obtain a sublist from a given list using slice() method which makes use of range of the elements indices.&lt;br /&gt;
&lt;br /&gt;
Example&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;, &amp;quot;four&amp;quot;, &amp;quot;five&amp;quot;)&lt;br /&gt;
    val resultList = theList.slice( 2..4)&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[three, four, five]&lt;br /&gt;
Removing null a List&lt;br /&gt;
We can use filterNotNull() method to remove null elements from a Kotlin list.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, null, &amp;quot;four&amp;quot;, &amp;quot;five&amp;quot;)&lt;br /&gt;
    val resultList = theList.filterNotNull()&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[one, two, four, five]&lt;br /&gt;
Filtering Elements&lt;br /&gt;
We can use filter() method to filter out the elements matching with the given predicate.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 20, 30, 31, 40, 50, -1, 0)&lt;br /&gt;
    val resultList = theList.filter{ it &amp;gt; 30}&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[31, 40, 50]&lt;br /&gt;
Dropping First N Elements&lt;br /&gt;
We can use drop() method to drop first N elements from the list.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 20, 30, 31, 40, 50, -1, 0)&lt;br /&gt;
    val resultList = theList.drop(3)&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[31, 40, 50, -1, 0]&lt;br /&gt;
Grouping List Elements&lt;br /&gt;
We can use groupBy() method to group the elements matching with the given predicate.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 12, 30, 31, 40, 9, -3, 0)&lt;br /&gt;
    val resultList = theList.groupBy{ it % 3}&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
{1=[10, 31, 40], 0=[12, 30, 9, -3, 0]}&lt;br /&gt;
Mapping List Elements&lt;br /&gt;
We can use map() method to map all elements using the provided function:.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 12, 30, 31, 40, 9, -3, 0)&lt;br /&gt;
    val resultList = theList.map{ it / 3 }&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[3, 4, 10, 10, 13, 3, -1, 0]&lt;br /&gt;
Chunking List Elements&lt;br /&gt;
We can use chunked() method to create chunks of the given size from a list. Last chunk may not have the elements equal to the number of chunk size based on the total number of elements in the list.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 12, 30, 31, 40, 9, -3, 0)&lt;br /&gt;
    val resultList = theList.chunked(3)&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[[10, 12, 30], [31, 40, 9], [-3, 0]]&lt;br /&gt;
Windowing List Elements&lt;br /&gt;
We can use windowed() method to a list of element ranges by moving a sliding window of a given size over a collection of elements.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 12, 30, 31, 40, 9, -3, 0)&lt;br /&gt;
    val resultList = theList.windowed(3)&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[[10, 12, 30], [12, 30, 31], [30, 31, 40], [31, 40, 9], [40, 9, -3], [9, -3, 0]]&lt;br /&gt;
By default, the sliding window moves one step further each time but we can change that by passing a custom step value:&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = listOf(10, 12, 30, 31, 40, 9, -3, 0)&lt;br /&gt;
    val resultList = theList.windowed(3, 3)&lt;br /&gt;
    &lt;br /&gt;
    println(resultList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[[10, 12, 30], [31, 40, 9]]&lt;br /&gt;
Kotlin mutable List&lt;br /&gt;
We can create mutable list using mutableListOf(), later we can use add() to add more elements in the same list, and we can use remove() method to remove the elements from the list.&lt;br /&gt;
&lt;br /&gt;
fun main() {&lt;br /&gt;
    val theList = mutableSetOf(10, 20, 30)&lt;br /&gt;
&lt;br /&gt;
    theList.add(40)&lt;br /&gt;
    theList.add(50)&lt;br /&gt;
    println(theList)&lt;br /&gt;
&lt;br /&gt;
    theList.remove(10)&lt;br /&gt;
    theList.remove(30)&lt;br /&gt;
    println(theList)&lt;br /&gt;
}&lt;br /&gt;
When you run the above Kotlin program, it will generate the following output:&lt;br /&gt;
&lt;br /&gt;
[10, 20, 30, 40, 50]&lt;br /&gt;
[20, 40, 50]&lt;br /&gt;
Quiz Time (Interview &amp;amp; Exams Preparation)&lt;br /&gt;
Q 1 - Can we make a mutable Kotlin list as immutable?&lt;br /&gt;
&lt;br /&gt;
A - Yes&lt;br /&gt;
&lt;br /&gt;
B - No&lt;br /&gt;
&lt;br /&gt;
Q 2 - We can add two or more lists and create a single list using + operator:&lt;br /&gt;
&lt;br /&gt;
A - True&lt;br /&gt;
&lt;br /&gt;
B - False&lt;br /&gt;
&lt;br /&gt;
Q 2 - What does the Kotlin list get() method do?&lt;br /&gt;
&lt;br /&gt;
A - It gets the list element from the given index.&lt;br /&gt;
&lt;br /&gt;
B - It returns all the values of the list&lt;br /&gt;
&lt;br /&gt;
C - There is no such method supported by list&lt;br /&gt;
&lt;br /&gt;
D - None of the above&lt;br /&gt;
&lt;br /&gt;
==Referensi==&lt;br /&gt;
&lt;br /&gt;
* https://www.tutorialspoint.com/kotlin/kotlin_lists.htm&lt;/div&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
</feed>