Difference between toString() method and new String() method
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. […]