添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
腹黑的板凳  ·  DateUtil (hutool ...·  6 小时前    · 
淡定的茶壶  ·  anti-emulator/AntiEmul ...·  7 小时前    · 
豪气的苹果  ·  Android social ...·  8 小时前    · 
风流倜傥的爆米花  ·  TDengine Go Connector ...·  9 小时前    · 
很酷的钢笔  ·  C++ STL IO流 与 Unicode ...·  12 小时前    · 
精明的菠菜  ·  Invoke Code Exception ...·  1 年前    · 
想发财的菠萝  ·  sql server日期减法-掘金·  1 年前    · 
体贴的扁豆  ·  黄叶村 ...·  1 年前    · 

Tutorial

Convert char to String in Java

Published on August 3, 2022
author

Pankaj

Convert char to String in Java

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Sometimes we have to convert char to String in java program. Here we will look into different methods you can convert character to string in java. We will also learn how to convert char array to String using different methods.

Convert char to String Java

convert char to string java Here is a simple program showing different ways to convert char to string in java.

package com.journaldev.string;
public class CharToStringJava {
	public static void main(String[] args) {
		// char to string
		char c = 'a';
		String str = String.valueOf(c);
		// using Character class
		str = Character.toString(c);
		// another way
		str = new Character(c).toString();
		// string concatenation - worst performance
		str = "" + c;
		// char array to string
		char[] ca = { 'a', 'b', 'c' };
		str = String.valueOf(ca);
		// recommended way
		str = new String(ca);

Let’s look at these methods one by one.

String.valueOf(char c)

Character.toString©

new Character©.toString();

String concatenation

String constructor

String.valueOf(char[] data)


About the authors
Default avatar
Pankaj

author

Still looking for an answer?

Ask a question Search for more help

Was this helpful?
JournalDev
DigitalOcean Employee
DigitalOcean Employee badge
May 18, 2019

Hi Pankaj, Code below prints incorrect value while doing string processing. How do we convert int[] to String . int[] is converted to by stream processing. public class StringFilter { public static void main(String[] args) { String test= “abcd”; int[] array = test.chars().toArray(); System.out.println(String.valueOf(array)); } }