title: How to implement trim() method in java by using only substring() method
body: <p>I know this question is quite silly, but in an interview I was told to implement trim() method without using any method from String class except substring() method.</p>
  
  <p>I approached this problem by using toCharArray() and then identifying the first and last valid character of String. But was told not to use toCharArray() method.</p>
  
  <p>Could anyone suggest some approach to do it.</p>
  
  <p>Overriden methods of Objects class are allowed like equals() and hashCode().</p>