Why isn't the following code working ? String s = "fecbda"; Arrays.sort(s.toCharArray()); System.out.println(s);
Why isn't the following code working ? String s = "fecbda"; Arrays.sort(s.toCharArray()); System.out.println(s);
Strings are immutable so you can't change them, and you shouldn't expect this to do anything.
What you might have intended is
String s = "fecbda";
char[] chars = s.toCharArray();
Arrays.sort(chars);
String s2 = new String(chars);
System.out.println(s2);
برچسب:
نویسنده: استخدام کار