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) */ */ }
 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 ) ; } }
  Kotlin Function function means use big problems divided by submodule and easily problems solved.   It makes reusability of code and makes the program more manageable There are two types of functions: Standard library function User-defined function Standard Library Function Kotlin Standard library function is built-in library functions import java.time.LocalDateTime fun main (args: Array < String >) { val current = LocalDateTime.now() println( "Current Date and Time is: $current " ) } User-defined Function A user-defined is created by the user. User-defined function takes the parameter(s), perform an action and return the result of that action as a value. fun  main(args: Array<String>){       sum()       print( "code after sum" )   }   fun  sum(){       var num1 = 5        var...