About 177,000 results
Open links in new tab
  1. java - How to convert a char to a String? - Stack Overflow

    Nov 17, 2011 · String(char[] value, boolean share) { // assert share : "unshared not supported"; this.value = value; } Source code from String.java in Java 8 source code. Hence String.valueOf(char) seems to be most efficient method, in terms of both memory and speed, for converting char to String. Sources: How to convert primitive char to String in Java

  2. How to convert/parse from String to char in java?

    Oct 21, 2011 · If you want to parse a String to a char, whereas the String object represent more than one character, you just simply use the following expression: char c = (char) Integer.parseInt(s). Where s equals the String you want to parse. Most people forget that char's represent a 16-bit number, and thus can be a part of any numerical expression :)

  3. Converting String to "Character" array in Java - Stack Overflow

    Apr 4, 2012 · I want to convert a String to an array of objects of Character class but I am unable to perform the conversion. I know that I can convert a String to an array of primitive datatype type "char" with the toCharArray() method but it doesn't help in converting a String to an array of objects of Character type. How would I go about doing so?

  4. java - How to convert a char array back to a string ... - Stack …

    Apr 11, 2015 · Note however, that this is a very unusual situation: Because String is handled specially in Java, even "foo" is actually a String. So the need for splitting a String into individual char s and join them back is not required in normal code.

  5. java - How to convert ASCII code (0-255) to its corresponding …

    Nov 2, 2016 · You're completely correct that something like Character.toString((char) i) is faster than String.valueOf(Character.toChars(i)). Running a quick benchmark of converting 1,000,000 random integers in the given range (100 times, to be safe) on my machine gives an average time of 153.07 nanoseconds vs. 862.39 nanoseconds.

  6. string - Convert character to ASCII numeric value in java - Stack …

    May 9, 2013 · Java uses Unicode for string and char. A textual unit in Unicode is a grapheme, which is a base codepoint followed by zero or more combining codepoints. A codepoint, in Java, is encoded in UTF-16, which could require one or two 16-bit code units (char) for a codepoint. To iterate codepoints, see this answer. Code should already be ready for the ...

  7. How to capitalize the first letter of a String in Java?

    Oct 11, 2010 · I am using Java to get a String input from the user. I am trying to make the first letter of this input capitalized. I tried this: String name; BufferedReader br = new InputStreamReader(System.in);

  8. How to convert a String to a Java 8 Stream of Characters?

    Oct 12, 2014 · If you want char values, you can use the IntStream returned by String.chars() and cast the int values to char without loss of information. The other answers explained why there's no CharStream primitive specialization for the Stream class. If you really want boxed Character objects, then use mapToObj() to convert from IntStream to

  9. java - Most efficient way to make the first character of a String …

    Oct 29, 2010 · Despite a char oriented approach I would suggest a String oriented solution. String.toLowerCase is Locale specific, so I would take this issue into account.

  10. Converting Char Array to List in Java - Stack Overflow

    All Operations can be done in java 8 or above: To the Character array from a Given String. char[] characterArray = myString.toCharArray(); To get the Character List from given String. ArrayList<Character> characterList = (ArrayList<Character>) myString.chars().mapToObj(c -> (char)c).collect(Collectors.toList());

Refresh