ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Kotlin program to convert string to character array

Kotlin | Convert string to character array: Here, we are going to learn how to convert a given string to the character array in Kotlin programming language?
Submitted by IncludeHelp, on May 05, 2020

Given a string, we have to convert it into a character array.

Example:

    Input:
    string = "IncludeHelp India Pvt Ltd"

    Output:
    char_arr = [I, n, c, l, u, d, e, H, e, l, p,  , I, n, d, i, a,  , P, v, t,  , L, t, d]

Program to convert string to character array in Kotlin

package com.includehelp

import java.util.*

//Main Function, entry Point of Program
fun main(args: Array<String>) {
    // InputStream to get Input
    val scanner = Scanner(System.`in`)

    //Input String
    print("Enter String : ")
    var str = scanner.nextLine()

    //convert String to Character Array
    val charArray = str.toCharArray()

    //Print Character Array get from String
    println("Character Array Elements  : ${charArray.contentToString()} ")
}

Output

Run 1:
-----
Enter String : IncludeHelp India Pvt Ltd
Character Array Elements  : [I, n, c, l, u, d, e, H, e, l, p,  , I, n, d, i, a,  , P, v, t,  , L, t, d]
--------
Run 2:
----
Enter String : Corona Virus Covid-19 Panidimic
Character Array Elements  : [C, o, r, o, n, a,  , V, i, r, u, s,  , C, o, v, i, d, -, 1, 9,  , P, a, n, i, d, i, m, i, c]
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.