Search code examples
javastringtrim

How to implement the logic of string trim() method


I have tried checking the internal implementation of String trim() , but could not get the complete idea.Can any one please explain the internal behaviour of trim() .I know that it removes the whitespaces.But while executing the below program, white spaces are not removed.

public class test
{
    public static void main(String [] args){
        String s = "  abd  c  ";
        String s3 = s.trim();
        System.out.println(s3);
    }
}

How to implement the internal logic of trim method...?


Solution

  • Trim does not remove spaces among the characters. It only removes from the beginning/end.