
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Joiner class Guava Java
Joiner provides various methods to handle joining operations on string, objects, etc. Let us see an example −
Example
import com.google.common.base.Joiner; import java.util.*; public class Demo{ public static void main(String[] args){ String[] my_arr = { "hel", null, "lo", "wo", "r", null, "ld" }; System.out.println("The original array is : "+ Arrays.toString(my_arr)); String my_result = Joiner.on('+').skipNulls().join(my_arr); System.out.println("The joined string is : " + my_result); } }
Output
The original array is [hel, null, lo, wo, r, null, ld] The joined string is hel+lo+wo+r+ld
A class named Demo contains the main function, which defines a string array. The array is converted to string and displayed on the string. The array also contains some null values. While displayed this array, the nulls are removed and replaced with the ‘+’ operator, all because of the Joiner class present in the Guava package. This output is displayed on the console.
- Related Articles
- Does guava contain citric acid?
- Java StringBuffer class.
- Java StringBuilder class.
- What is the class "class" in Java?
- Final class in Java
- Abstract class in Java
- Object class in Java
- Java String Class Tutorial
- StringTokenizer class in Java
- Timer Class in Java
- Static class in Java
- Java Float Wrapper Class
- GregorianCalendar Class in Java
- Date Class in Java
- CopyOnWriteArraySet Class in Java

Advertisements