Sorting Strings by Contained Numbers in Java 1. Introduction In this tutorial, we’ll look at how to sort alphanumeric Strings by the numbers they contain. We’ll focus on removing all non-numeric characters from the String before sorting multiple Strings by the numerical characters that remain. We’ll look at common edge cases, including empty Strings… Continue Reading java-sort-strings-contained-numbers

Guava CharMatcher In this quick tutorial we’ll explore the CharMatcher utility class in Guava. 1. Remove Special Characters from a String Let’s start by removing all special characters from a String. In the following example, we remove all characters that aren’t digit or letter using retainFrom(): @Test public void whenRemoveSpecialCharacters_thenRemoved(){… Continue Reading guava-string-charmatcher

How to Remove the Last Character of a String? 1. Overview In this quick article, we are going to check and discuss different techniques for removing the last character of a String. 2. Using String.substring() The easiest way is to use the built-in substring() method of the String class. In… Continue Reading java-remove-last-character-of-string

StringBuilder and StringBuffer in Java 1. Overview In this short article, we’re going to look at similarities and differences between StringBuilder and StringBuffer in Java. Simply put, StringBuilder was introduced in Java 1.5 as a replacement for StringBuffer. 2. Similarities Both StringBuilder and StringBuffer create objects that hold a mutable… Continue Reading java-string-builder-string-buffer