List of usage examples for java.lang String toCharArray
public char[] toCharArray()
From source file:Main.java
public static Hashtable<Character, Integer> createHashtable(String text) { Hashtable<Character, Integer> textHashTable = new Hashtable<Character, Integer>(); for (char c : text.toCharArray()) { if (textHashTable.get(c) != null) { Integer temp = textHashTable.get(c); textHashTable.put(c, temp + 1); } else {//from ww w .j av a2 s . c om textHashTable.put(c, new Integer(1)); } } return textHashTable; }
From source file:Main.java
public static boolean isChineseChar(String value) { try {//from ww w . j ava 2 s.com if (value == null) return false; char[] chars = value.toCharArray(); for (int i = 0; i < chars.length; i++) { String target = String.valueOf(chars[i]); byte[] b = target.getBytes(); if (b.length == 2) { } else { return false; } } return true; } catch (Exception e) { return false; } }
From source file:Main.java
public static String convertCamelCaseToAllCaps(String qualifiedClassName) { StringBuffer sb = new StringBuffer(); final char[] charArray = qualifiedClassName.toCharArray(); for (int c = 0; c < charArray.length; c++) { char character = charArray[c]; final boolean isEnd = c + 1 == charArray.length; boolean nextIsUpper = !isEnd && Character.isUpperCase(charArray[c + 1]); boolean nextNextIsLower = c + 2 < (charArray.length) && Character.isLowerCase(charArray[c + 2]); sb.append(Character.toUpperCase(character)); if (Character.isLowerCase(character) && nextIsUpper) { sb.append('_'); } else {/*from w ww . j a v a 2 s. c om*/ if (nextIsUpper && nextNextIsLower) { sb.append('_'); } } } return sb.toString(); }
From source file:io.opencensus.contrib.spring.aop.CensusSpringSqlAspect.java
private static String makeSpanName(ProceedingJoinPoint call, String sql) { String hash = Integer.toHexString(hashCode(sql.toCharArray())); return call.getSignature().getName() + "-" + hash; }
From source file:mx.bigdata.cfdi.security.KeyLoader.java
public static PrivateKey loadPKCS8PrivateKey(InputStream in, String passwd) throws Exception { byte[] decrypted = (passwd != null) ? getBytes(in, passwd.toCharArray()) : getBytes(in); PKCS8EncodedKeySpec keysp = new PKCS8EncodedKeySpec(decrypted); KeyFactory kf = KeyFactory.getInstance("RSA"); return kf.generatePrivate(keysp); }
From source file:Main.java
public static String escaped(String raw) { StringBuilder ret = new StringBuilder(); for (char c : raw.toCharArray()) { switch (c) { case '\"': ret.append("""); break; case '\'': ret.append("'"); break; case '<': ret.append("<"); break; case '>': ret.append(">"); break; case '&': ret.append("&"); break; default://w w w.j a v a2 s. c om ret.append(c); break; } } return ret.toString(); }
From source file:gov.nih.nci.calims2.util.serialization.SerializationHelper.java
/** * Deserialize an object from an hexadecimal string. * @param s The string to deserialize/*from ww w . j a v a2s .c om*/ * @return The deserialized object */ public static Serializable deserializeFromHex(String s) { try { return (Serializable) SerializationUtils.deserialize(Hex.decodeHex(s.toCharArray())); } catch (DecoderException e) { throw new RuntimeException("String is probably not hexadecimal", e); } }
From source file:Main.java
/** * Convert a string to html content, Same as the xml version * except that spaces and tabs are converted. * @param tabIcon the icon to represent a tag. * @param str the string to convert. * @return the converted string./* ww w . ja v a2 s .c o m*/ */ public static String escapeHTMLContent(String tabIcon, String str) { final StringBuilder b = new StringBuilder(); final char[] chars = str.toCharArray(); for (int i = 0; i < chars.length; ++i) { final char c = chars[i]; switch (c) { case '<': b.append("<"); break; case '>': b.append(">"); break; case '&': b.append("&"); break; case ' ': b.append(" "); break; case '\t': b.append("<img src='" + tabIcon + "' title='tab'/>"); b.append(" "); break; default: b.append(c); } } return b.toString(); }
From source file:Strings.java
/** * Returns an array of substrings of the specified string, * in order, with divisions before and after any instance * of the specified character. The returned array will always * have at least one element. Elements in the returned array * may be empty. The following examples illustrate this behavior: * * <br/><br/>// ww w. j a va 2 s. c o m * <table border="1" cellpadding="5"> * <tr><td><b>Call</b></td><td><b>Result</b></td></tr> * <tr> * <td><code>split("",' ')</code></td> * <td><code>{ "" }</code></td> * </tr> * <tr> * <td><code>split("a",' ')</code></td> * <td><code>{ "a" }</code></td> * </tr> * <tr> * <td><code>split("a b",' ')</code></td> * <td><code>{ "a", "b" }</code></td> * </tr> * <tr> * <td><code>split("aaa bb cccc",' ')</code></td> * <td><code>{ "aaa", "bb", "cccc" }</code></td> * </tr> * <tr> * <td><code>split(" a",' ')</code></td> * <td><code>{ "", "a" }</code></td> * </tr> * <tr> * <td><code>split("a ",' ')</code></td> * <td><code>{ "a", "" }</code></td> * </tr> * <tr> * <td><code>split(" a ",' ')</code></td> * <td><code>{ "", "a", "" }</code></td> * </tr> * </table> * * @param s String to split. * @param c Character on which to split the string. * @return The array of substrings resulting from splitting the * specified string on the specified character. */ public static String[] split(String s, char c) { char[] cs = s.toCharArray(); int tokCount = 1; for (int i = 0; i < cs.length; ++i) if (cs[i] == c) ++tokCount; String[] result = new String[tokCount]; int tokIndex = 0; int start = 0; for (int end = 0; end < cs.length; ++end) { if (cs[end] == c) { result[tokIndex] = new String(cs, start, end - start); ++tokIndex; start = end + 1; } } result[tokIndex] = new String(cs, start, cs.length - start); return result; }
From source file:Main.java
public static byte[] hexStringToByte(String hex) { int len = hex.length() / 2; byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (int i = 0; i < len; i++) { int pos = i * 2; result[i] = (byte) (toByte(achar[pos]) << 4 | toByte(achar[(pos + 1)])); }/*from w ww . j av a 2s . c o m*/ return result; }