SmartString is a lightweight Java library for string case conversion, pluralization, and fluent string transformations.
It provides both:
SmartStringUtils– static utility methodsSmartString– a fluent chainable wrapper
The library is dependency-free, fast, and designed for everyday backend or tooling tasks.
- Convert between common naming conventions
- Fluent chainable API
- Singular ↔ plural conversion
- Support for irregular word mappings
- Zero external dependencies
- Small and fast
<dependency>
<groupId>io.github.uncaughterrol</groupId>
<artifactId>smartstring</artifactId>
<version>0.1.0</version>
</dependency>implementation 'io.github.uncaughterrol:smartstring:0.1.0'SmartString provides a chainable API for transforming strings.
import io.github.uncaughterrol.smartstring.SmartString;
public class Example {
public static void main(String[] args) {
String result = SmartString.of("user_profile")
.toCamelCase()
.toPlural()
.capFirst()
.getValue();
System.out.println(result);
// UserProfiles
}
}If you prefer static utility methods, you can use SmartStringUtils.
import io.github.uncaughterrol.smartstring.SmartStringUtils;
public class Example {
public static void main(String[] args) {
String snake = SmartStringUtils.toSnakeCase("HelloWorldExample");
System.out.println(snake);
// hello_world_example
String camel = SmartStringUtils.toCamelCase("hello_world");
System.out.println(camel);
// helloWorld
String pascal = SmartStringUtils.toPascalCase("hello_world");
System.out.println(pascal);
// HelloWorld
}
}import io.github.uncaughterrol.smartstring.SmartStringUtils;
public class Example {
public static void main(String[] args) {
System.out.println(SmartStringUtils.toPlural("city"));
// cities
System.out.println(SmartStringUtils.toPlural("box"));
// boxes
System.out.println(SmartStringUtils.toPlural("dog"));
// dogs
}
}import io.github.uncaughterrol.smartstring.SmartStringUtils;
public class Example {
public static void main(String[] args) {
System.out.println(SmartStringUtils.toSingular("cities"));
// city
System.out.println(SmartStringUtils.toSingular("boxes"));
// box
}
}You can define irregular plural mappings in:
irregular-mapping.properties
Example:
children=child
men=man
women=woman
people=person
The file is automatically loaded from the classpath.
MIT License