Java String Interpolation with Examples

In this article, we will look at the concept of String Interpolation. We will look at its description, the need for String Interpolation. Also, we look at different techniques to perform String Interpolation with implementation in Java. String Interpolation is a process where we evaluate a String containing one or more Placeholders (Temporary Name or Substitute) by replacing it with their corresponding values. It allows to dynamically print out text output. So, in short String Interpolation allows us to put

Read more

Convert String to Byte Array or Byte Array to String in Java

Sometimes we need to convert Strings into Bytes because of several reasons like, to save content to the file, sending data over a network or it can be any other reason. So in this tutorial we’ll see how we can convert string to byte array or byte array to string in Java. Convert String to Byte Array in Java Method 1: Using String.getBytes()

Output: Platform’s encoding = [[email protected] Contents of byte Array = [84, 104, 101, 32, 67, 114,

Read more

String Constant Pool in Java

What is String Constant Pool in Java? It is a special memory area in Heap that contains references of string objects. There are two ways to create string object in Java. 1. Using string literal Example: String s = “java”; A string written inside double quotes is called string literal. Whenever we create string literal the JVM checks string constant pool. If the string is already present in pool then its reference is fetched. If the string is not present

Read more

Difference between String and StringBuffer in Java

Difference between String and StringBuffer or String vs StringBuffer is a very commonly asked java interview question. Both String and StringBuffer classes are used to store and manage sequence of characters but still there are some differences between them that I have explained in this tutorial. Difference between String and StringBuffer in Java Mutability String class is immutable. It means once an object is assigned a value it can’t be changed. Example:

In above case total two objects are

Read more

How to Encode or Decode URL Parameters in Java

Here you will learn how to encode or decode url parameters in java. When we submit a form by using GET method then the parameters are automatically encoded and appended to the url. In situation when we have to send data using url without submitting form then we have to append the parameters to url. The url may look like this. In this case the parameter value contains special characters like space, comma, etc. So we have to encode

Read more

4 Ways to Reverse String in Java

In this tutorial you will learn about different ways to reverse string in java with examples.   For example: Input: Hello World Output: dlroW olleH Ways to Reverse String in Java Method 1: This is the simplest method in which we iterator through given string from end character by character and append to new empty string.

  Output Original String: I love programming Reversed String: gnimmargorp evol I   Method 2: It is also an iterative method in which

Read more

2 Ways to Convert String to Character Array in Java

Here you will learn about different ways to convert string to character array in java. 1. Using String.toCharArray() Method We can easily convert string to character array using String.toCharArray() method. It can be done in following way.

  Output I   L o v e   J a v a    2. Writing Own Logic We can also writing our own logic. Each character of string is extracted using String.charAt() method and inserted into the character array.


Read more

4 Ways to Check String is Anagram in Java

In this tutorial I will tell you the four different ways to check string is anagram in Java or not. Two strings are anagram if they contains same characters in different order. For example word and odwr are anagrams.     Ways to Check String is Anagram in Java Method 1 In this method we sort the strings using Arrays.sort() method and then compare them using Arrays.equals() method. If strings are equal then they are anagram.

  Output Enter first

Read more
1 2