# Using the Kotlin standard library in Java

DevFeed: [Using the Kotlin standard library in Java](<https://devfeed.tech/articles/using-the-kotlin-standard-library-in-java-25888.md>)

Original publisher: [Read original article](<https://medium.com/google-developer-experts/using-the-kotlin-standard-library-in-java-ea0766deac10?source=rss-1331e67af4e1------2>)

Author: Danny Preussler

Published: 2021-06-14T19:01:08Z

Content type: tutorial

Language: en

Sources: [Stories by Danny Preussler on Medium](<https://devfeed.tech/sources/stories-by-danny-preussler-on-medium.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Java](<https://devfeed.tech/topics/java.md>), [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [collections](<https://devfeed.tech/tags/collections.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-beginners](<https://devfeed.tech/tags/kotlin-beginners.md>), [kotlin-standard-library](<https://devfeed.tech/tags/kotlin-standard-library.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

## AI overview

This tutorial explains how Java code can use Kotlin standard-library functions through static imports. It covers list creation, Kotlin free functions compiled into classes, and extension functions exposed to Java with the receiver as the first argument.

## Source excerpt

Using the Kotlin standard library from Javagiphy.com If you work with Kotlin on a daily basis you probably love the language and don't want to go back to Java. Though, many of us work on a codebase that isn't purely Kotlin. Our Android codebase at SoundCloud still has a fair amount of code written in Java. This percentage gets smaller over time but there is no urgent need for mass migration of the remains right now. Therefore, every once in a while, I find myself, changing Java files. In those cases, I miss some of the Kotlin functions I'm used to; I can easily think of string manipulation or handling collections as examples. Of course, Java has powerful utility libraries such as Googles Guava or Apache Commons, libraries many of which we used to work with in the world before Kotlin. But when writing Kotlin code all day, remembering those "older" APIs is sometimes hard. It is a complete context switch. It would be much easier to use what we use in Kotlin. And you should! Let me show you! Let's assume we want to create a list of items. In Kotlin, we would write: val items = listOf( items1, item2, item3 ) In Java, I would write it as: List<Item> items = Arrays.asList(item1, item2, items3); Usage is pretty much the same but you still need to remember the name of the function. Wouldn't it be easier to just use: List<Item> items = listOf(item1, item2, items3); And yes you can! All you need to do is to static importthat function! This works aslistOf, like many of our daily Kotlin utility functions, are simply static functions you can use from Java. And even better, as your project already uses Kotlin, you already got those dependencies included anyway, no additional library needed. A closer look If you would click on the details of listOf from Kotlin, you would end up in a file called Collections.kt and the definition looks like this: public fun <T> listOf(vararg elements: T): List<T> It is a free function, not bound to any class. But from a Java perspective this looks so