java char转换成string string转换成char

char->string

char[] a=....

String s=String.valueof(a);

String ->char

char[] b=s.toCharArray();

例:

import java.util.*;
public class huiwen{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
System.out.println("-----------------------");
String s=sc.nextLine();
//string 转混成char
char[] a=s.toCharArray();
System.out.println("string转换成char");
for(int i=0;iSystem.out.print(a[i]);
System.out.println();
System.out.println("char转换成string");
//char转换成string
String s2=String.valueOf(a);
System.out.println(s2);
}
}

}

你可能感兴趣的:(java,string转换成char,char转换成String,java,刷题)