What is the Java equivalent of Trim(‘/’) in C# [duplicate]

Here is how to do the same in Java:

 String xx = "/test/file2/".replaceAll("(^/*|/*$)", "");

This uses a regex that matches multiple / from the beginning or multiple / at the end and replaces them with void.

Leave a Comment