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

 Firebase Cloud Messaging With  push notification with Image  public class ImageDownload extends AsyncTask < String , Void , Bitmap >{ @Override protected Bitmap doInBackground ( String ... strings ) { InputStream inputStream ; try { URL url = new URL( strings [ 0 ]) ; try { HttpURLConnection connection = ( HttpURLConnection ) url .openConnection() ; connection .connect() ; inputStream = connection .getInputStream() ; return BitmapFactory . decodeStream ( inputStream ) ; } catch ( IOException e ) { e .printStackTrace() ; } } catch ( MalformedURLException e ) { e .printStackTrace() ; } return null; } @Override protected void onPostExecute ( Bitmap bitmap ) { ShowNotification( bitmap ) ; } }
In this tutorial, I will show how can I save String Android Internal Storage .txt file  Nested Class: 1.File file 2.FileOutputStream fileOutputStream 3.OutputStreamWriter outputStreamWriter Step 1: Android Manifest.xml Permission Add <? xml version ="1.0" encoding ="utf-8" ?> <manifest xmlns: android ="http://schemas.android.com/apk/res/android" package ="com.ruhul.string_save_txt_format" > <uses-permission android :name ="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission> <application android :allowBackup ="true" android :icon ="@mipmap/ic_launcher" android :label ="@string/app_name" android :roundIcon ="@mipmap/ic_launcher_round" android :supportsRtl ="true" android :theme ="@style/Theme.String_save_txt_format" > <activity android :name =".MainActivity" &
 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