About 145,000 results
Open links in new tab
  1. 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 :)

  2. 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

  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. convert string to arraylist <Character> in java - Stack Overflow

    Mar 11, 2013 · How to convert a String without separator to an ArrayList<Character>. My String is like this: String str = "abcd..." I know one way of doing this is converting the String to char[] first, and then convert the char [] to ArrayList <Character>. Is there any better way to do this? like converting directly?

  5. java - Split string into array of character strings - Stack Overflow

    Jan 27, 2017 · In Java 8 the behavior of String.split was slightly changed so that leading empty strings produced by a zero-width match also are not included in the result array, so the (?!^) assertion that the position is not the beginning of the string becomes unnecessary, allowing the regex to be simplified to nothing – "cat".split("") – but in Java 7 and below that produces a leading empty string in ...

  6. How do I convert a String to an int in Java? - Stack Overflow

    Alternatively, you can use an Ints method from the Guava library, which in combination with Java 8's Optional, makes for a powerful and concise way to convert a string into an int: import com.google.common.primitives.Ints; int foo = Optional.ofNullable(myString) .map(Ints::tryParse) .orElse(0)

  7. Converting A String To Hexadecimal In Java - Stack Overflow

    Jul 26, 2024 · Java 17 introduces a utility class for hexadecimal formatting: java.util.HexFormat. Convert to hex: public String toHex(String value) { return HexFormat.of().formatHex(value.getBytes()); } Convert from hex: public String fromHex(String value) { return new String(HexFormat.of().parseHex(value)); } More about HexFormat here. Documentation: here

  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. In Java how does one turn a String into a char or a ... - Stack …

    char firstLetter = someString.charAt(0); String oneLetter = String.valueOf(someChar); You find the documentation by identifying the classes likely to be involved. Here, candidates are java.lang.String and java.lang.Character. You should start by familiarizing yourself with: Primitive wrappers in java.lang; Java Collection framework in java.util

  10. java - How to convert CharSequence to String? - Stack Overflow

    Oct 10, 2011 · Type Casting: String string = (String) charSequence; Calling toString(): String string = charSequence.toString(); String.valueOf() Method: String string = String.valueOf(charSequence); And if we run these where CharSequence charSequence = "a simple string"; then all 3 of them will produce the expected result.

Refresh