Joining a List in Java with commas and “and”
In Java 8 you can use String.join() like following: Collection<String> elements = ….; String result = String.join(“, “, elements);
In Java 8 you can use String.join() like following: Collection<String> elements = ….; String result = String.join(“, “, elements);
The class was moved from package org.apache.commons.lang3 to org.apache.commons.text You can replace the deprecated library easily: In your build.gradle: implementation ‘org.apache.commons:commons-text:1.9’ And in your class using StringEscapeUtils make sure you import the correct class: import org.apache.commons.text.StringEscapeUtils; 1.9 is currently the newest version (last checked February 24th 2021) but you can check the versions at maven: … Read more
Here is what I could turn up: RFC 4648 It includes this convenient table: Table 1: The Base 64 Alphabet Value Encoding Value Encoding Value Encoding Value Encoding 0 A 17 R 34 i 51 z 1 B 18 S 35 j 52 0 2 C 19 T 36 k 53 1 3 D 20 … Read more
Tomcat DBCP is just a renamed version of Apache Commons DBCP, with also a different internal package name prefix. At build time, Tomcat fetches the Commons DBCP sources (the version depends on the Tomcat version, for instance Tomcat 7.0.27 uses Commons DBCP 1.4), and does package name replacement (org.apache.commons -> org.apache.tomcat.dbcp) and builds the result … Read more
One approach I have used successfully is to use slf4j as my primary logging API. I then have slf4j bind to log4j. 3rd party dependencies using other frameworks (like JUL) can be bridged to slf4j.
All standard implementations of java.util.List already implement java.io.Serializable. So even though java.util.List itself is not a subtype of java.io.Serializable, it should be safe to cast the list to Serializable, as long as you know it’s one of the standard implementations like ArrayList or LinkedList. If you’re not sure, then copy the list first (using something … Read more
Of course not. Do you really think “” is not clear enough ? Constants have essentially 3 use cases: Document the meaning of a value (with constant name + javadoc) Synchronize clients on a common value. Provide a shortcut to a special value to avoid some init costs None apply here.
You are mixing the 1.5.6 version of the jcl bridge with the 1.6.0 version of the slf4j-api; this won’t work because of a few changes in 1.6.0. Use the same versions for both, i.e. 1.6.1 (the latest). I use the jcl-over-slf4j bridge all the time and it works fine.
You can use the Google Collections API for that, recently renamed to Guava, specifically a BiMap A bimap (or “bidirectional map”) is a map that preserves the uniqueness of its values as well as that of its keys. This constraint enables bimaps to support an “inverse view”, which is another bimap containing the same entries … Read more
First of, as javamonkey79 explained, while Google Guava and Apache Commons do share similar features, they also both have functionality that is absent from their counterpart. Thus, limiting yourself to only one library might be unwise. That being said, if I had to choose, I’d opt to use Guava, keeping Apache Commons around for the … Read more