Example usage for java.lang String toCharArray

List of usage examples for java.lang String toCharArray

Introduction

In this page you can find the example usage for java.lang String toCharArray.

Prototype

public char[] toCharArray() 

Source Link

Document

Converts this string to a new character array.

Usage

From source file:Main.java

public static void main(String[] argv) {
    String str = "java2s.com";
    char[] chars = str.toCharArray();
    System.out.println(Arrays.toString(chars));
}

From source file:Main.java

public static void main(String args[]) {
    String str = "Hello World";
    char[] stringArray = str.toCharArray();
    for (int index = 0; index < stringArray.length; index++)
        System.out.print(stringArray[index]);
}

From source file:Main.java

public static void main(String[] args) {
    String literal = "Examples";

    char[] temp = literal.toCharArray();

    for (int i = 0; i < temp.length; i++) {
        System.out.print(temp[i]);
    }/*from  ww w  . j  av  a  2s. c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    String str = "Abcdefg";
    char[] cArray = str.toCharArray();

    for (char c : cArray)
        System.out.println(c);//from  w w w. j av  a  2  s .c om
}

From source file:Main.java

public static void main(String[] arg) {
    String text = "To be or not to be";
    char[] textArray = text.toCharArray();
    for (char ch : textArray) {
        System.out.println(ch);// www . j  ava 2  s  .c o  m
    }
}

From source file:Main.java

public static void main(String[] args) {
    HashMap<Character, Integer> map = new HashMap<Character, Integer>();
    String test = "BUNANA";
    char[] chars = test.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        if (!map.containsKey(chars[i])) {
            map.put(chars[i], 1);/*from   w  ww .  ja v  a 2  s .  c o  m*/
        }
        map.put(chars[i], map.get(chars[i]) + 1);
    }

    System.out.println(map.toString());
}

From source file:MainClass.java

public static void main(String[] arg) {
    String text = "To be or not to be";
    char[] textArray = text.toCharArray();

    for (char ch : textArray) {
        System.out.println(ch);/*from   ww  w . jav a2s . c o m*/

    }
}

From source file:Main.java

public static void main(String[] args) {
    Map<Character, Integer> counting = new HashMap<Character, Integer>();
    String testcase1 = "this is a test";
    for (char ch : testcase1.toCharArray()) {
        Integer freq = counting.get(ch);
        counting.put(ch, (freq == null) ? 1 : freq + 1);
    }/*from   w ww.  jav  a  2s . c om*/
    System.out.println(counting.size() + " distinct characters:");
    System.out.println(counting);
}

From source file:Main.java

public static void main(String[] args) {
    String str = "this is a test";
    char[] char_array = str.toCharArray();

    Map<Character, Integer> charCounter = new TreeMap<Character, Integer>();
    for (char i : char_array) {
        charCounter.put(i, charCounter.get(i) == null ? 1 : charCounter.get(i) + 1);
    }//from  www .j  a  v a  2 s .  c  o m
    for (Character key : charCounter.keySet()) {
        System.out.println("occurrence of '" + key + "' is  " + charCounter.get(key));
    }
}

From source file:Main.java

public static void main(String[] args) {
    String input = "This is a sentence";
    char[] charinput = input.toCharArray();
    Stack<String> stack = new Stack<String>();
    for (int i = input.length() - 1; i >= 0; i--) {
        stack.push(String.valueOf(charinput[i]));
    }//from  w ww .  j a va2 s.  com
    StringBuilder StackPush = new StringBuilder();
    for (int i = 0; i < stack.size(); i++) {
        StackPush.append(stack.get(i));
    }
    System.out.println(StackPush.toString());
}