Questions tagged [apache-commons-lang]

The standard Java libraries fail to provide enough methods for manipulation of its core classes. Apache Commons Lang provides these extra methods.

Apache Commons Lang provides a host of helper utilities for the java.lang API, notably string manipulation methods, basic numerical methods, object reflection, concurrency, creation and serialization and System properties. Additionally it contains basic enhancements to java.util.Date and a series of utilities dedicated to help with building methods, such as hashCode(), toString() and equals().

Note that Lang 3.0 (and subsequent versions) use a different package (org.apache.commons.lang3) than the previous versions (org.apache.commons.lang), allowing it to be used at the same time as an earlier version.

Official Website: http://commons.apache.org/lang/

Useful Links:

Related Tags:

76 questions
47
votes
4 answers

Why was org.apache.common.lang3 StringEscapeUtils deprecated?

I couldn't find any explanation why StringEscapeUtils was deprecated from Apache Lang3 v3.7. https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html What are we supposed to use now for HTML…
gene b.
  • 6,760
  • 9
  • 49
  • 122
24
votes
2 answers

Alternative to using StringEscapeUtils.escapeJavaScript() in commons lang3

I've been tasked with updating our code from using org.apache.commons.lang to org.apache.commons.lang3 and I've found that the newer version of StringEscapeUtils no longer has the method escapeJavaScript() however we were using this in quite a few…
Popeye
  • 10,831
  • 9
  • 52
  • 85
17
votes
3 answers

What sort of equality does the Apache Commons ObjectUtils equals method test for?

I have always understood there to be two types of equality in Java, value equality : uses the .equals() method to test that two objects implement an equivalence relation on non-null object references. reference equality : uses the == operator to…
Caoilte
  • 2,275
  • 1
  • 20
  • 25
16
votes
2 answers

How do exclude a single variable using ToStringBuilder

I have an object that includes a number of variables but one is a byteArray e.g. public class DataWithFields { private String string1; private String string2; .... private byte[] data public String toString() { return…
user1605665
  • 2,651
  • 6
  • 27
  • 46
13
votes
3 answers

Migrating StringEscapeUtils.escapeSql from commons.lang

I have started to migrate commons.lang 2 to commons.lang3. According to https://commons.apache.org/proper/commons-lang/article3_0.html StringEscapeUtils.escapeSql This was a misleading method, only handling the simplest of possible SQL cases. >As…
Michael
  • 9,061
  • 16
  • 53
  • 96
11
votes
6 answers

Is StringUtils.isNumeric() method specification logically correct?

Apache's StringUtils.isNumeric() method specification says: Checks if the String contains only unicode digits. A decimal point is not a unicode digit and returns false. Null will return false. An empty String ("") will return true. Is this logically…
Andriy Sholokh
  • 794
  • 2
  • 5
  • 14
11
votes
3 answers

How have RecursiveToStringStyle and JSON_STYLE using commons-lang3

I'm using the dependency: org.apache.commons commons-lang3 3.4 I have the following objects: public Class X { private…
Leonel
  • 2,276
  • 4
  • 18
  • 35
10
votes
4 answers

Make ReflectionToStringBuilder skip fields with null values

I have to print object values in log file. I used: ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE, true, true); But it also prints null values which I don't want to include, for…
saravanan_jay
  • 115
  • 1
  • 5
9
votes
11 answers

masking a creditcard number in java

I tried to mask the characters in a creditcard number string using character 'X'.I wrote two functions as below .The second function uses commons.lang.StringUtils class .I tried to find the time it takes in both cases public static String…
jimgardener
  • 587
  • 2
  • 9
  • 25
8
votes
2 answers

Replace CompareToBuilder with Java 8's Comparator.comparing(...).thenComparing(...)

Before Java 8, we implemented Comparable.compareTo(...) like this: public int compare(Person a, Person b) { return new CompareToBuilder() .append(a.getLastName(), b.getLastName()) .append(a.getFirstName(),…
7
votes
2 answers

Javadoc of ArrayUtils.isNotEmpty is faulty?

The javadoc of ArrayUtils.isNotEmpty() in Apache Commons Lang seems to be wrong. Or, at least, misleading. It says Returns: true if the array is not empty or not null In my understanding, an empty array is not null. So, according to the…
Ulrich Scholz
  • 1,701
  • 4
  • 24
  • 44
7
votes
1 answer

Parsing numbers safely and locale-sensitively

Java's NumberFormat is 1) non thread-safe (which can be worked around with a ThreadLocal); 2) inconvenient to use correctly for the simplest use case when I know whether the string should contain int, long, or double, and want an API like: int…
Alexey Romanov
  • 154,018
  • 31
  • 276
  • 433
6
votes
2 answers

Is there Commons AnnotationUtils like library? (Java)

I can't find a general utilities (static methods) library for querying for annotations other than either using the annotations api directly and writing my own or using Springs: Springs Annotation Utils Normally I would not mind using Springs but…
Adam Gent
  • 44,449
  • 20
  • 142
  • 191
6
votes
1 answer

IntegerUtils and DoubleUtils in Apache Commons package

I use the Apache Commons package extensively, especially the StringUtils, BooleanUtils, ObjectUtils, MapUtils classes and find them extremely helpful. I am wondering if there are classes such as IntegerUtils, DoubleUtils that provide a similar…
Venk K
  • 1,137
  • 5
  • 14
  • 25
5
votes
1 answer

Apache Commons Lang: Can the "incompatibilities" between 'lang' and 'lang3' cause different runtime results?

My code uses Apache Commons Lang v.2 (commons-lang). If I update my code to use v.3 (commons-lang3) instead, should I worry that my code might start to behave differently (of course except differences due to fixed bugs and to possible new bugs,…
1
2 3 4 5 6