Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to convert char[] to trimmed String

Tags:

java

string

trim

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.

like image 302
Enzomatric Avatar asked Aug 20 '14 08:08

Enzomatric


1 Answers

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.

like image 109
Suresh Atta Avatar answered Nov 14 '22 15:11

Suresh Atta