This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
// Your ArrayList of Integers | |
ArrayList<Integer> arrayList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); | |
// Convert it to a primitive int[] array | |
int[] primitiveArray = arrayList.stream() | |
.mapToInt(Integer::intValue) | |
.toArray(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class CustomRecordExample { | |
// Your static nested class is defined here | |
static class Record { | |
int first; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
// 1. Define an empty mutable 2D list | |
val twoDList = mutableListOf<MutableList<Int>>() | |
println("1. Initial empty mutable list: $twoDList") | |
// 2. Add inner lists to it later | |
twoDList.add(mutableListOf(10, 20, 30)) | |
twoDList.add(mutableListOf(40, 50, 60)) | |
println("2. Mutable list after adding rows: $twoDList") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Example: | |
* var ti = TreeNode(5) | |
* var v = ti.`val` | |
* Definition for a binary tree node. | |
* class TreeNode(var `val`: Int) { | |
* var left: TreeNode? = null | |
* var right: TreeNode? = null | |
* } | |
*/ |
OlderNewer