amitshekhariitbhu /from-java-to-kotlin

From Java To Kotlin - Your Cheat Sheet For Java To Kotlin

★ 6,324⑂ 776
JavaCreated 2017-05-21outcomeschool.com
6,324
stars
+-2+-4+-1
776
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

From Java To Kotlin

 From Java To Kotlin - Your Cheat Sheet For Java To Kotlin

 About me

Hi, I am Amit Shekhar, Founder @ Outcome School • IIT 2010-14 • I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

 Follow Amit Shekhar

- X/Twitter
- LinkedIn
- GitHub

 Follow Outcome School

- YouTube
- X/Twitter
- LinkedIn
- GitHub

 I teach at Outcome School

- AI and Machine Learning
- Android

Join Outcome School and get a high-paying tech job: Outcome School

 Live session on "Android Developer Interview Preparation for Product-based Companies"

I conducted a live session on "Android Developer Interview Preparation for Product-based Companies"

Interacted with over 500 Android Developers.

Guided, motivated, and inspired them to aim higher and achieve more.

Recording Link: https://drive.google.com/file/d/1VWW3l_itH6vYbNYzNer6XW5_x0jzOF4O/view?usp=sharing

Document Link: https://docs.google.com/document/d/14UdD7Gd1j3no583ALx2t2Ggt3G_CECYhenLE-m-bkzA/edit?usp=sharing

 Print to Console
 Java

java
System.out.print("Amit Shekhar");
System.out.println("Amit Shekhar");


 Kotlin

kotlin
print("Amit Shekhar")
println("Amit Shekhar")


---
 Constants and Variables
 Java

java
String name = "Amit Shekhar";
final String name = "Amit Shekhar";


 Kotlin

kotlin
var name = "Amit Shekhar"
val name = "Amit Shekhar"


---
 Assigning the null value
 Java

java
String otherName;
otherName = null;


 Kotlin

kotlin
var otherName : String?
otherName = null


---
 Verify if value is null
 Java

java
if (text != null) {
  int length = text.length();
}


 Kotlin

kotlin
text?.let {
    val length = text.length
}
// or simply
val length = text?.length


---
 Verify if value is NotNull  OR NotEmpty
 Java
java
String sampleString = "Shekhar";
if (!sampleString.isEmpty()) {
    myTextView.setText(sampleString);
}
if(sampleString!=null && !sampleString.isEmpty()){
    myTextView.setText(sampleString); 
}

 Kotlin

kotlin
var sampleString ="Shekhar"
if(sampleString.isNotEmpty()){  //the feature of kotlin extension function
    myTextView.text=sampleString
}
if(!sampleString.isNullOrEmpty()){
   myTextView.text=sampleString 
}

---
 Concatenation of strings
 Java

java
String firstName = "Amit";
String lastName = "Shekhar";
String message = "My name is: " + firstName + " " + lastName;


 Kotlin

kotlin
var firstName = "Amit"
var lastName = "Shekhar"
var message = "My name is: $firstName $lastName"


---
 New line in string
 Java

java
String text = "First Line\n" +
              "Second Line\n" +
              "Third Line";


 Kotlin

kotlin
val text = """
        |First Line
        |Second Line
        |Third Line
        """.trimMargin()


---

 Substring
 Java

java
String str = "Java to Kotlin Guide";
String substr = "

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON