Search code examples
javastringtrim

Fastest way to convert char[] to trimmed String


In my program I need to convert char[] of fixed size into trimmed String (without blank spaces taken from an array). At the moment I do new String(array).trim() but I would like to avoid trim() if possible. Any advice how to do it better? Best Regards.


Solution

  • but I would like to avoid trim() if possible. Any advice how to do it better?

    Do not look for any alternative and trim() is smart enough which uses substring() method internally. That is fast enough.

    Any looping or reg-ex based solutions will hit you hard.