Replace StringBuffer with StringBuilder and add initial capacity. StringBuilder is faster because it is not synchronized.