Home » string

Tag Archives: string

Char Array to String Java Example

Hello readers! In this tutorial, we feature an example on how to convert a Char Array to String in Java. We will learn different ways of this conversion. Meanwhile, you can also check the String to Char Array Example. 1. Introduction Java programming offers possible ways to convert a character array (char []) to String. A new String is allocated ...

Read More »

Java 8 StringJoiner Example

Hello readers, in this tutorial, we will learn about the Java8 Stream’s API StringJoiner feature and we will explore its different characteristics. 1. Introduction These days in the programming universe joining multiple strings are a common task among the developers. In the ancient Java world, there was no direct way to join the multiple strings. Java8 has introduced a final ...

Read More »

Groovy String Example

1. Introduction String related manipulations have been always important in almost all programming languages. If you are using Groovy, you will do String manipulation in an easy way. In other words, it is very easy to split, add, manipulate, initialize, escape Strings in Groovy. In this tutorial I will show you how to use Groovy String efficiently.       ...

Read More »

StringBuffer Java Example

In this example, we are going to present the StringBuffer class in Java, and StringBuffer vs StringBuilder which is contained in the java.lang package. We are going to show some of its most important uses and methods, and explain why and when it should be used, as well as the difference between StringBuffer and String. 1. String vs StringBuffer Strings in ...

Read More »

Java String Array Example

Last updated Jan. 14, 2019 In this example we will show how to declare and populate a Java String Array as well as how to iterate through all its elements. 1. Example of Java String Array Create a java class named JavaStringArrayExample.java with the following code: JavaStringArrayExample.java package com.javacodegeeks.javabasics.stringarray; public class JavaStringArrayExample { public static void main(String args[]) { // ...

Read More »

Compare Strings

In this example we shall show you how to compare Strings. We are using the methods that the String class provides. To compare Strings one should perform the following steps: Create two new String objects. Use the compareTo(String anotherString) to compare the two Strings. This method compares two strings lexicographically. The comparison is based on the Unicode value of each ...

Read More »

String replace method

With this example we are going to demonstrate how to use the replace method of String class. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. In short, to replace a String you should: Create a new String. Use replace(char oldChar, char newChar) API method. This method ...

Read More »

String trim method

This is an example of how to use the trim method of String class. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Trimming a String implies that you should: Create a new String. Use trim() method of String. This method returns a copy of the string, ...

Read More »

Java Convert String toLowerCase

In this example, we shall show you how to convert a String toLowerCase in Java. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. 1. Java Convert String toLowerCase To convert a String toLowerCase in Java, one should perform the following steps: Create a new StringUse toLowerCase() ...

Read More »