Ruang penulis
← Kembali ke jurnal
Core API

How do I convert string to char array?

Here we have a small class that convert a string literal into an array, a character array. To do this we can simply use String.toCharArray() method. package org.kodejava.lang; public class StringToArrayExample { public static void main(String[] args) { // We have a string literal that contains the tag line of this blog. String literal = […]

DWayan · 25 Sep 2006 · 1 menit baca

Artikel oleh Wayan · Sumber: Kode Java ↗

Terjemahan artikel ini belum tersedia. Isi asli ditampilkan.

Here we have a small class that convert a string literal into an array, a character array. To do this we can simply use String.toCharArray() method.

package org.kodejava.lang;

public class StringToArrayExample {
    public static void main(String[] args) {
        // We have a string literal that contains the tag line of this blog.
        String literal = "Kode Java - Learn Java by Examples";

        // Now we want to convert or divided it into a small array of char.
        // To do this we can simply used String.toCharArray() method. This
        // method splits the string into an array of characters.
        char[] temp = literal.toCharArray();

        // Here we just iterate the char array and print it to our console.
        for (char c : temp) {
            System.out.print(c);
        }
    }
}
← Jelajahi catatan lainnya