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.
More Related Contents:
- Why does the if statement “if(1)” give error in Java but it holds true in C++?
- What is the difference between a variable, object, and reference? [duplicate]
- How to round up the result of integer division?
- How to access the Java method in a C++ application
- Is Short Circuit Evaluation guaranteed In C++ as it is in Java?
- Calling a java method from c++ in Android
- Access private field of another object in same class
- Call c function from Java
- Embed Java into a C++ application?
- Interview question: Check if one string is a rotation of other string [closed]
- What is fatal signal 6 in android logcat [closed]
- What does the registerNatives() method do?
- What is more efficient, i++ or ++i? [duplicate]
- Use custom Manifest file and permission in Unity?
- What is LD_LIBRARY_PATH and how to use it?
- Use a .jar java library API in C#?
- is there a Java equivalent to null coalescing operator (??) in C#? [duplicate]
- Does java really have pointers or not? [closed]
- How does subtracting the character ‘0’ from a char change it into an int?
- What’s wrong with using associativity by compilers?
- Java – C-Like Fork?
- Java equivalent to #region in C#
- Proper implementation of cubic spline interpolation
- Crossplatform iPhone / Android code sharing
- JNI Calls different in C vs C++?
- Is it possible to use sun.misc.Unsafe to call C functions without JNI?
- Failed to write core dump. Core dumps have been disabled
- Convert static windows library to dll
- SWIG (v1.3.29) generated C++ to Java Vector class not acting properly
- How to use the same C++ code for Android and iOS?