Kotlin vs Java

Also
Java
final var original = "abc"

System.out.println(original);
System.out.println(new StringBuilder(input).reverse().toString());
System.out.println(original.length());
Kotlin
val original = "abc"

original.also {
    println("The original String is $it") // "abc"
}.also {
    println("The reverse String is ${it.reversed()}") // "cba"
}.also {
    println("The length of the String is ${it.length}") // 3
}
Apply
Java
public MyFragment createInstance(Bundle args) {
    final var fragment = new MyFragment();
    fragment.setArguments(args);
    return fragment;
}
Kotlin
fun createInstance(args: Bundle) = MyFragment().apply { arguments = args }
Let
Java
final var original = "abc"
// Map the value and send to the next chain

Optional.of(original)
        .map(
            str -> {
                System.out.println("The original String is " + str); // "abc"
                val result = new StringBuilder(input).reverse().toString();
                return result;
            }
        ).map(
            reversed -> {
                System.out.println("The reverse String is " + reversed); // "cba"
                val result = reversed.length();
                return result;
            }
        ).map(
            length -> {
                System.out.println("The length of the String is " + length); // 3
                return length;
            }
        )
Kotlin
val original = "abc"
// Map the value and send to the next chain
original.let {
    println("The original String is $it") // "abc"
    it.reversed() // map it as parameter to send to next let
}.let {
    println("The reverse String is $it") // "cba"
    it.length  // can be evolved to other type
}.let {
    println("The length of the String is $it") // 3
}
Let and apply
Java
public File makeDir(String path) {
    final var result = new File(path);
    result.mkdirs();
    return result;
}
Kotlin
fun makeDir(path: String) =
        path.let { File(it) }
            .also { it.mkdirs() }
Run
Java
if (webview.settings != null) {
    final var settings = webview.settings;
    settings.javaScriptEnabled = true;
    settings.databaseEnabled = true;
}
Kotlin
webview.settings?.run {
    javaScriptEnabled = true
    databaseEnabled = true
}
TakeIf
Java
public void displaySubstringPosition(final String input, final String sub) {
    final var index = input.indexOf(sub);
    if (index >= 0) {
        System.out.println("The substring " + sub + "is found in " + input + ".");
        System.out.println("Its start position is " + index + ".");
    }
}
Kotlin
fun displaySubstringPosition(input: String, sub: String) {
    input.indexOf(sub).takeIf { it >= 0 }?.let {
        println("The substring $sub is found in $input.")
        println("Its start position is $it.")
    }
}
With
Java
val numbers = List.of("one", "two", "three");
with(numbers) {
    final var firstItem = numbers.get(0);
    final var lastItem = numbers.get(numbers.size() - 1);
    System.out.println("First item: " + firstItem + ", last item: " + lastItem);
}
Kotlin
val numbers = mutableListOf("one", "two", "three")
with(numbers) {
    val firstItem = first()
    val lastItem = last()
    println("First item: $firstItem, last item: $lastItem")
}