class Solution {
public String restoreString(String s, int[] indices) {
char a[]=s.toCharArray();
char arr[]=new char[s.length()];
if(s.length()==indices.length)
{
for(int i=0;i<s.length();i++)
{
arr[indices[i]]=s.charAt(i);
}
}
return new String(arr);
}
}
In the above problem, Why we are using new String method instead of toString method
I tried toString method , and I got error on that code. I want to clarify the difference between toString() and new String();
New contributor
JANANI C R is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.