How to filter array of a positive integer and negative integer in kotlin

Interviews are asking a general question nowadays from Kotlin developers so that I like to give its answer

fun main(){
    var lis  = arrayOf(1,-2,3,-22,10)
    val postiveList = lis.filter { it >0 }
    val negativeList = lis.filter { it <0 }
    print("Positive Number"+postiveList)
    println("Negative  Number"+negativeList)

}

Output

Positive Number[1, 3, 10]Negative Number[-2, -22]


要查看或添加评论,请登录

Rajendra Verma的更多文章

  • Experiment with Location, geofencing, and a MQTT button

    Experiment with Location, geofencing, and a MQTT button

    TL;DR, This Saturday I did experiment with my Node-RED server and some geo fencing APIs. I create a location-sensitive…

  • My First AI Model

    My First AI Model

    If you will check the below table, then you will get to know that Y is dependent on X and the relationship is. y = 2x -…

  • Evolution of Neural Network

    Evolution of Neural Network

    This is a very intersecting topic, just like an Netflix webseries. Now a days everyone is talking about AI, but no one…

  • What is Deep Learning?

    What is Deep Learning?

    A subset of machine learning: Deep learning is a branch of machine learning that focuses on using artificial neural…

  • Very Good CLI vs Flutter CLI: A Clear Distinction

    Very Good CLI vs Flutter CLI: A Clear Distinction

    We all know about Flutter cli, that it is known to develop the project and that it works to update and upgrade the…

  • Flutter Internationalization

    Flutter Internationalization

    When you create a mobile app and it hits the international market, you have to internationalize the app which is an…

  • Mixin in dart

    Mixin in dart

    Flutter is becoming the most popular language now for mobile development. When developers write code, they encounter…

  • Types of provider in Flutter

    Types of provider in Flutter

    I was working on one of my Flutter projects, and suddenly I thought that it is a good idea to explain the difference…

  • Flutter

    Flutter

    A couple of days ago, I was thinking of learning to flutter because of market requirements. But I find it too easy and…

  • My Experiment with the Matter Protocol

    My Experiment with the Matter Protocol

    Exploring the Future of IoT: An In-Depth Look at the Matter Protocol As a software engineer specializing in IoT…

社区洞察

其他会员也浏览了