add java solution for TrailingString