我的代码比较了两个单词之间的相等性.如果字符串相等,它会打印一个值"TRUE".否则它返回false.正在使用Java"等于"功能
class k{
public static void main(String args[]){
String s1="Sach";
String s2=word();
String s3=new String("Sach");
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
}
public static String word() {
char[] str=new char[100];
str[0]='S';
str[1]='a';
str[2]='c';
str[3]='h';
String ss=new String(str);
System.out.println(ss);
return ss;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要将一些选定的字母提取到数组中并将其转换为字符串.转换后,该函数返回字符串.但是比较会导致错误的值.是否有其他方法将数组转换为字符串,以便此程序提供正确的结果.