Skip to main content

 kotlin Array Types


import com.sun.xml.internal.fastinfoset.util.StringArray
import java.util.*

fun main() {

/* scanner object*/
val Sc = Scanner(System.`in`)

/* array in Mutable but has fixed size */
/*array declaration system */
val idvalue = Array<Int>(5) { 0 }

for (i in idvalue.indices) {
println("please input value [$i] = ")
idvalue[i] = Sc.nextInt()
}
for (v in idvalue) {
println(v)
}


/* array declaration two type:
1.explicit
2.implicit

*/

/* explicit type declaration*/
val language = arrayOf<String>("kotlin", "java", "php", "python")

language.set(0, "java")
language.set(1, "kotlin")

println("language [0]=" + language.get(0))
println("language [1]=" + language.get(1))

for (values in language) {
println("language: " + values)
}


/* implicit type declaration*/
var id = arrayOf(1, 2, 3, 4, 5)

/* Kotlin also has some built-in factory methods to create arrays of primitive data types,
such as byteArray, intArray, shortArray, etc. */

var bytearray_demo = byteArrayOf(1, 2, 3, 4, 5)
var Shortarray_demo = shortArrayOf(1, 2, 3, 4, 5)
var intarray_demo = intArrayOf(1, 2, 3, 4, 5)
var floatarray_demo = floatArrayOf(1f, 2f, 3f, 4f, 5f)
var doublearray_demo = doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0)
var longarray_demo = longArrayOf(1, 2, 3, 4, 5)


var Student_id = intArrayOf(1, 2, 3, 4, 5)

for (id in Student_id) {
println(id)
}
println("another array print---")
for (id in 0..Student_id.size - 1) {
println("student id [$id =]" + " : " + Student_id[id])
}


}

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