Skip to main content

 All Collection Type Details  in Kotlin


fun main(args: Array<String>) {


/* collectin of Two Types
1.immutable (immutable means : Collection only Read)
2.Mutable (Mutable means : Collection Read and Write)
*/

/* 1.immutable collection:
1.listof
2.mapof
3.setof
*/
val idlistof = listOf<Int>(1, 1, 1, 1)
val idlistof_without_type = listOf(1, 1, 1, 1)

val idmapof = mapOf<String, String>("1" to "ruhul", "2" to "amin")
val idmapof_without_type = mapOf("1" to "ruhul", "2" to "amin")
val idmapof_defrentdata_without_type = mapOf("1" to "ruhul", 2 to "amin")

val setof = setOf<String>("Asia", "Urop")
val idsetof_without_type = setOf("Asia", "Urop")

/* 1.mutable collection:

1.mutable list
1.Arraylist
2.arrayListof
3.mutableListof

2.mutable map
1.HashMap
2.hasMapof
3.mutablemapof

3.mutable set

1.mutablesetof
2.hassetof
*/

/* 1. mutable list */
var arraylist = ArrayList<String>()

var arraylistof = ArrayList<String>()

arraylistof.add("Bangladseh")
arraylistof.add("Indonesia")

print("mutable arraylistof: " + arraylistof.get(0))

val mutablelistof = mutableListOf("java")
val mutablelistof_withexplecit_type = mutableListOf<Int>(510)
mutablelistof.add(0, "kotlin")


/* 2. mutable map */


val mutable_hasmap = HashMap<String, String>(2)
mutable_hasmap.put("name", "ruhul")
mutable_hasmap.put("country", "Bangladesh")

val mutable_hasmapof = hashMapOf<String, String>("1" to "ruhul", "2" to "amin")
val idhasmapof = hashMapOf<Int, String>(1 to "ruhul", 2 to "amin")
idhasmapof.put(3, "Bangladesh")
for (idhas in idhasmapof) {
println(idhas)
}

val mutablemapof = mutableMapOf<Int, String>(1 to "python", 2 to "java")
mutablemapof.put(3, "php")

for (id in mutablemapof) {
println(id)
}


/* 3. mutable set */

var mutableset = mutableSetOf<String>("Ban", "indo")
mutableset.add("ka")
//var mutableset = mutableSetOf("Ban","indo")
for (country in mutableset) {
println(country)
}

var hassetof = hashSetOf("ruhul")
//var hassetof = hashSetOf<String>()
hassetof.add("ruhul")
hassetof.add("amin")
hassetof.add("ruhul")


}

Comments

Popular posts from this blog

 var val  deference in kotlin  fun main () { var Android_Programing_language : String = "java" println ( "android official programing language: " + Android_Programing_language ) Android_Programing_language = "Kotline" println ( "2019 google announced android official programing language: " + Android_Programing_language ) val Android_MultiPlatform_language : String = "Dart" println ( "multiple device run : " + Android_MultiPlatform_language ) /* Android_MultiPlatform_language="" /* note: var--------------valu changable note: val--------------valu not changable (final) */ */ }
 phone authentication in android using Firebase Step 1:    Add Firebase to your Android project Step 2: Add this line build.Gradle(project) // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() jcenter() } dependencies { classpath "com.android.tools.build:gradle:4.1.1" classpath 'com.google.gms:google-services:4.3.5' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { google() jcenter() } } task clean( type : Delete) { delete rootProject . buildDir } Step 3: Add this dependency build.Gradle (app level) plugins { id 'com.android.application' } android { compileSdkVersion 30 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.ruhul.firebasephone...
  Android  Location Permissions With  GPS  disabled Enable Hello Everyone, In this Tutorial I Will Show you how Can I Get Android Location Permission Granted. In Case There is a Common Problemes When User Allow Permission Granted but not Gps Enable. So how Can I Solve This Problemes Flow this Step Step 1: AndroidManifest.xml  file  Permission add <uses-permission android :name ="android.permission.INTERNET" /> <uses-permission android :name ="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android :name ="android.permission.ACCESS_BACKGROUND_LOCATION" /> Step 2: Android XML Design Simple Button like  <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: app ="http://schemas.android.com/apk/res-auto" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_pa...