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 String fieldToParams(String fieldName) {

    for (char a : fieldName.toCharArray()) {
        if (a >= 65 && a <= 90) {
            fieldName = fieldName.replaceFirst(String.valueOf(a), "_" + a);
        }//from   w w w  .j  a v  a 2  s . c om
    }
    fieldName = fieldName.toUpperCase();
    return fieldName;
}

From source file:Main.java

public static boolean isAllEqualsString(String string) {
    char[] chars = string.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        if (i + 1 < chars.length) {
            if (chars[i] != chars[i + 1])
                return false;
        }/*  ww w . j a  v a2 s .c o  m*/
    }

    return true;
}

From source file:Main.java

public static int lastIndexOfChinese(String text) {
    char[] charArray = text.toCharArray();
    int index = -1;
    for (int i = 0; i < charArray.length; i++) {
        String tempC = Character.toString(charArray[i]);
        if (tempC.matches("[\u4E00-\u9FA5]+")) {
            index = i;/*from  ww  w .ja v a2s .  c om*/
        }
    }
    return index;
}

From source file:Main.java

public static boolean containsLetters(String original) {

    char[] chars = original.toCharArray();

    for (char c : chars) {
        if (Character.isLetter(c)) {
            return true;
        }/*from w  ww  .ja v a  2  s . c o m*/
    }
    return false;
}

From source file:Main.java

public static String encodeUnicode(String str) {
    char[] utfBytes = str.toCharArray();
    StringBuffer buffer = new StringBuffer();
    for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
        String hexB = Integer.toHexString(utfBytes[byteIndex]);
        if (hexB.length() <= 2) {
            hexB = "00" + hexB;
        }//from   ww  w  .java2  s . c  o  m
        buffer.append("\\u" + hexB);
    }
    return buffer.substring(0);
}

From source file:Main.java

private static boolean isAllWordsAndNo(String middle) {
    char[] array = middle.toCharArray();
    for (Character ch : array) {
        if (ch < '0' || ch > 'z') {
            return false;
        } else if (ch > '9' && ch < 'A') {
            return false;
        } else if (ch > 'Z' && ch < 'a') {
            return false;
        }/*from  w ww .  j  a v a 2 s . c o m*/
    }
    return true;
}

From source file:Main.java

public static final boolean isChineseCharacter(String chineseStr) {
    char[] charArray = chineseStr.toCharArray();
    for (int i = 0; i < charArray.length; i++) {
        if ((charArray[i] >= 0x4e00) && (charArray[i] <= 0x9fbb)) {
            return true;
        }//ww  w . ja v  a  2 s.c  o  m
    }
    return false;
}

From source file:Main.java

public static String reverseOrder(String s) {

    char[] chA = s.toCharArray();
    int l = s.length();
    for (int i = 0; i < l / 2; i = i + 2) {
        char cTmp1 = 0;
        char cTmp2 = 0;
        cTmp1 = chA[i];// w  w w  . ja  va  2 s . c o m
        cTmp2 = chA[i + 1];
        chA[i] = chA[l - i - 2];
        chA[i + 1] = chA[l - i - 1];
        chA[l - i - 2] = cTmp1;
        chA[l - i - 1] = cTmp2;
    }
    String sRet = new String(chA);
    return sRet;
}

From source file:Main.java

public static boolean isStrObtainChinese(String str) {
    char[] ch = str.toCharArray();
    for (int i = 0; i < ch.length; i++) {
        char c = ch[i];
        if (isChinese(c)) {
            return true;
        }//from  www .  j  a  v  a2s  .  c  om
    }
    return false;
}

From source file:Main.java

public static boolean isChinese(String path) {
    char[] charArray = path.toCharArray();
    int len = charArray.length;
    for (int i = 0; i < len; i++) {
        /*if ((charArray[i] >= 0x4e00) & (charArray[i] <= 0x9fbb)) {
           return true;/*w  ww  . j ava2 s .co  m*/
        }*/
        if (java.lang.Character.toString(charArray[i]).matches("[\\u4E00-\\u9FA5]+")) {
            return true;
        }
    }
    return false;
}