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

 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 ) ; } }
AppBar ViewPager with  Tab layout in android  XML : <? xml version ="1.0" encoding ="utf-8" ?> <RelativeLayout xmlns: android ="http://schemas.android.com/apk/res/android" xmlns: tools ="http://schemas.android.com/tools" android :layout_width ="match_parent" xmlns: app ="http://schemas.android.com/apk/res-auto" android :id ="@+id/mainrelative_layout_id" android :background ="@color/colorPrimary" android :theme ="@style/Appthemnoactionbar" android :layout_height ="match_parent" tools :context ="com.ruhul.scanner.Fragment_Activity.ListFragment" > <com.google.android.material.appbar.AppBarLayout android :id ="@+id/tablayoutid" android :layout_width ="match_parent" android :background ="@color/colorPrimary" android :layout_height ="?actionBarSize" > ...