Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use StringUtils in Java?

Tags:

java

I'm a beginner in Java. I want to use StringUtils.replace but Eclipse outputs "StringUtils cannot be resolved".

I tried import java.lang.*;, but it doesn't work.

like image 205
Leo Jiang Avatar asked Dec 28 '11 19:12

Leo Jiang


People also ask

How do you use StringUtils in spring boot?

Take a String that is a delimited list and convert it into a String array. Take a String that is a delimited list and convert it into a String array. Test if the given String ends with the specified suffix, ignoring upper/lower case. Extract the filename from the given Java resource path, e.g.

What is StringUtils join in Java?

Overview. join() is a static method of the StringUtils class that is used to join the elements of the provided array/iterable/iterator/varargs into a single string containing the provided list of elements.

What is StringUtils substring?

Overview. In Java, substring() is a static method of the StringUtils class that returns the string between the given start and end index. Negative start and end index positions can be used to specify offsets relative to the end of the string.


2 Answers

java.lang does not contain a class called StringUtils. Several third-party libs do, such as Apache Commons Lang or the Spring framework. Make sure you have the relevant jar in your project classpath and import the correct class.

like image 133
Jonik Avatar answered Sep 21 '22 05:09

Jonik


StringUtils is an Apache Commons project. You need to download and add the library to your classpath.

To use:

import org.apache.commons.lang3.StringUtils; 
like image 36
Erhan Bagdemir Avatar answered Sep 24 '22 05:09

Erhan Bagdemir