Search code examples
javaconcurrencystringbuffer

What's the StringBuffer alternative for String.endsWith?


I have been using string in concurrent application and to make the code more optimized,i have to use StringBuffer instead of String? But I am confused what is the alternative of string.endsWith("\\") for StringBuffer. What method of StringBuffer should be used for the mentioned purpose?


Solution

  • There is no direct API. You could try try stringBuffer.lastIndexOf("\\")==stringBuffer.length()-1

    OR

    stringBuffer.charAt(stringBuffer.length()-1)=='\\'

    PS : The above code samples are untested.