How to change char to String

Asked 1 years ago, Updated 1 years ago, 136 views

I want to change the char data type to String. How do I do it

string java type-conversion

2022-09-21 20:18

1 Answers

Write Character.toString(char).

Or

1. String stringValueOf = String.valueOf('c'); // most efficient

2. String stringValueOfCharArray = String.valueOf(new char[]{x});

3. String characterToString = Character.toString('c');

4. String characterObjectToString = new Character('c').toString();

   // // Although this method seems very simple, 
   // // this is less efficient because the concatenation
   // // expands to new StringBuilder().append(x).append("").toString();
5. String concatBlankString = 'c' + "";

6. String fromCharArray = new String(new char[]{x});

There's a way like this.


2022-09-21 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.