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:

80 questions
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,157
  • 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,…
5
votes
2 answers

Apache DateUtils truncate for WEEK

I'm using Apache commons-lang3 DateUtils.truncate(Calendar calendar, int field) method to 'cut off' unnecessary fields of a Calendar object. Now when the field parameter gets the value of Calendar.WEEK_OF_MONTH, it throws…
Sleeper9
  • 1,707
  • 1
  • 19
  • 26
4
votes
1 answer

Benefits of using NumberUtils.INTEGER_ONE and other such utilities

In java for a comparison in an if statement, I wrote if (x == 1) and got a comment in code review to use NumberUtils.INTEGER_ONE instead of 1. I was wondering what benefit does it actually add to the code.
4
votes
1 answer

How to use FastDateFormat to create Date object using String

I used SimpleDataFormat and it seems to be not a very thread safe thing to use. Then I found that FastDateFormat is the alternative to this problem. But I'm trying to figure out how to use it in order to parse String with Date and Time. Here is a…
dinesh707
  • 12,106
  • 22
  • 84
  • 134
4
votes
3 answers

Check if the user input ending with alphabet "F" is a number

I need to check if the user input is a string or a number. I use the below statement for the purpose, Double.parseDouble(string); It works in most of the scenarios, but fails when the input entered by the user is like 123F This should be…
Anand B
  • 2,997
  • 11
  • 34
  • 55
4
votes
1 answer

Why is ArrayUtils.add not adding the element here

I use ArrayUtils.add(double[], double) with some frequency. Apparently I have a blind spot for why it's not working here. Can anyone help? double[] reliableNeighborValues = new double[1]; for (int j = 0; j < 8; j++) { if (pixelInfo[j] > 0) { …
barnhillec
  • 346
  • 1
  • 5
  • 15
3
votes
2 answers

What is the Commons Lang and how do I use it? (Java)

I was trying to find a way to do some string manipulation and ran across the Commons Lang in a response to another question posted here on stackoverflow. From what I can tell it's a collection of libraries, do I have to download and somehow import…
Daisetsu
  • 4,846
  • 11
  • 50
  • 70
3
votes
1 answer

how can I use StrSubstitutor with and empty variable suffix?

I am trying to use Apache Commons Lang's StrSubstitutor to replace variables in a string marked only using prefixes, e.g. like named parameters markjed with : in an SQL query. Here's the code snippet I am using, which doesn't work. import…
Amnon
  • 2,212
  • 1
  • 19
  • 35
3
votes
1 answer

What is the Guava equivalent to StringUtils.removeEnd?

I struggle to find a Guava equivalent for commons-lang StringUtils.removeEnd. Is there such a method or do I have to use a Joiner and a Splitter in some way?
Tim Büthe
  • 62,884
  • 17
  • 92
  • 129
3
votes
1 answer

Apache Commons Lang: Upgrade from 2.3 to 3.3.1 - What about UnhandledException

I recently upgraded the Apache Commons version of my project (commons-lang) from version 2.3 to version 3.3.1 (latest stable). In my code there was usage of specific Exception like UnhandledException and I am just wondering which is the replacement…
рüффп
  • 5,172
  • 34
  • 67
  • 113
2
votes
3 answers

Numeric validation in Commons Lang

While using the org.apache.commons.lang.math.NumberUtils.isNumber(String str) function, I see that passing a string like "1f" passes validation while passing "1a" fails. What kind of alphabets are allowed here?
Victor
  • 16,609
  • 71
  • 229
  • 409
2
votes
1 answer

Java strsubstitutor with double $$ varaible

I have a question about the strsubstitutor with double $$ varible, I have the following code: Map params = new HashMap(); params.put("hello", "hello"); String templateString = "The ${hello} $${test}."; StrSubstitutor…
ratzip
  • 1,571
  • 7
  • 28
  • 53
2
votes
0 answers

StringEscapeUtils.escapeHtml/escapeHtml4 inconsistent between commons-lang and commons-lang3

unit test shows StringEscapeUtils.escapeHtml/escapeHtml4 don't produce same results. trying to upgrade commons-lang(2.6) to commons-lang3(3.9) and found parity-mismatch in escapeHtml/escapeHtml4 methods. for (String s : Stream.generate(()->…
Ron Reynolds
  • 544
  • 5
  • 10
2
votes
1 answer

What is the difference between Apache Common's StrBuilder and Java's StringBuilder?

How is StrBuilder from Apache Commons different from Java's StringBuilder? In Apache Commons I see StrBuilder is deprecated. import org.apache.commons.lang3.text.StrBuilder; StrBuilder sb = new StrBuilder(); Can I use Java's StringBuilder…