Zak Dyer

Zak Dyer


How to convert an Array to String in Java?

Below are the various methods to convert an Array to String in Java:

1. Arrays.toString() method:

Arrays.toString() method is used to return a string representation of the contents of the specified array. The string representation consists of a list of the array’s elements, enclosed in square brackets (“[]”). Adjacent elements are separated by the characters “, ” (a comma followed by a space). It returns “null” if the array is null.

// Java program to demonstrate 
// working of Arrays.toString() 

import java.util.*; 

class GFG { 
	public static void main(String[] args) 

		// Let us create different types of arrays and 
		// print their contents using Arrays.toString() 
		boolean[] boolArr 
			= new boolean[] { true, true, false, true }; 
		char[] charArr 
			= new char[] { 'g', 'e', 'e', 'k', 's' }; 
		double[] dblArr 
			= new double[] { 1, 2, 3, 4 }; 
		int[] intArr 
			= new int[] { 1, 2, 3, 4 }; 
		Object[] objArr 
			= new Object[] { 1, 2, 3, 4 }; 

			"Boolean Array: "
			+ Arrays.toString(boolArr)); 
			"Character Array: "
			+ Arrays.toString(charArr)); 
			"Double Array: "
			+ Arrays.toString(dblArr)); 
			"Integer Array: "
			+ Arrays.toString(intArr)); 
			"Object Array: "
			+ Arrays.toString(objArr)); 


Boolean Array: [true, true, false, true]
Character Array: [g, e, e, k, s]
Double Array: [1.0, 2.0, 3.0, 4.0]
Integer Array: [1, 2, 3, 4]
Object Array: [1, 2, 3, 4]

2. StringBuilder append(char[]):

The java.lang.StringBuilder.append(char[]) is the inbuilt method which appends the string representation of the char array argument to this StringBuilder sequence.

// Java program to illustrate the 
// StringBuilder.append(char[]) method 

import java.lang.*; 

public class Geeks { 

	public static void main(String[] args) 

		StringBuilder sbf 
			= new StringBuilder("We are geeks "); 

		// Char array 
		char[] astr 
			= new char[] { 'G', 'E', 'E', 'k', 'S' }; 

		// Appends string representation of char 
		// array to this String Builder 
		System.out.println("Result after"
						+ " appending = "
						+ sbf); 

		sbf = new StringBuilder("We are -"); 

		// Char array 
		astr = new char[] { 'a', 'b', 'c', 'd' }; 

		/* Appends string representation of char 
				array to this StringBuilder */
		System.out.println("Result after appending = " + sbf); 


We are geeks 
Result after appending = We are geeks GEEkS
We are -
Result after appending = We are -abcd

#java #arrays #string

What is GEEK

Buddha Community

How to convert an Array to String in Java?
Tyrique  Littel

Tyrique Littel


How to Install OpenJDK 11 on CentOS 8

What is OpenJDK?

OpenJDk or Open Java Development Kit is a free, open-source framework of the Java Platform, Standard Edition (or Java SE). It contains the virtual machine, the Java Class Library, and the Java compiler. The difference between the Oracle OpenJDK and Oracle JDK is that OpenJDK is a source code reference point for the open-source model. Simultaneously, the Oracle JDK is a continuation or advanced model of the OpenJDK, which is not open source and requires a license to use.

In this article, we will be installing OpenJDK on Centos 8.

#tutorials #alternatives #centos #centos 8 #configuration #dnf #frameworks #java #java development kit #java ee #java environment variables #java framework #java jdk #java jre #java platform #java sdk #java se #jdk #jre #open java development kit #open source #openjdk #openjdk 11 #openjdk 8 #openjdk runtime environment

Joseph  Murray

Joseph Murray


How to Print an Array in Java


Printing an array is a quick way to give us visibility on the values of the contents inside. Sometimes the array values are the desired output of the program.

In this article, we’ll take a look at how to print an array in Java using four different ways.

While the “best way” depends on what your program needs to do, we begin with the simplest method for printing and then show more verbose ways to do it.

#java #array #how to print an array in java #array in java #print an array in java #print

Joseph  Murray

Joseph Murray


String Array In Java: Java String Array With Coding Examples

In Java, Array refers to a crucial data structure used to collect and store multiple data types from primitive to user-defined. String array is the array of various objects where each of its elements is a string. Users can perform several operations on these components, like adding a component, sorting, joining, searching, splitting, etc.

Introduction To A String Array In Java

It is possible to have an array with strings in Java as its derived elements. This means that users can define ‘String Array’ as an array that holds a certain number of string values or strings. In other words, it refers to a structure that is widely used in Java for having the string value. For instance, even the number of arguments of the prime function in Java refers to a string array.

#software development #array in java #java #string array

Samanta  Moore

Samanta Moore


Functions for Strings in Java

In this tutorial, you will learn how to make better use of built-in functions for Strings in Java to program more quickly, effectively, and aesthetically.

What Is a String?

Firstly, of course, we have to initialize our string. What is a string used for?

  • You want to look at your string as a line, not as a mass of symbols.
  • If you have a long text, you want to work with the words, not the letters.
  • If you have lots of information, you need functions that solve questions as quickly as possible.

#java #tutorial #java strings #java tutorial for beginners #java string #string tutorial

Samanta  Moore

Samanta Moore


Going Beyond Java 8: Local Variable Type Inference (var) - DZone Java

According to some surveys, such as JetBrains’s great survey, Java 8 is currently the most used version of Java, despite being a 2014 release.

What you are reading is one in a series of articles titled ‘Going beyond Java 8,’ inspired by the contents of my book, Java for Aliens. These articles will guide you step-by-step through the most important features introduced to the language, starting from version 9. The aim is to make you aware of how important it is to move forward from Java 8, explaining the enormous advantages that the latest versions of the language offer.

In this article, we will talk about the most important new feature introduced with Java 10. Officially called local variable type inference, this feature is better known as the **introduction of the word **var. Despite the complicated name, it is actually quite a simple feature to use. However, some observations need to be made before we can see the impact that the introduction of the word var has on other pre-existing characteristics.

#java #java 11 #java 10 #java 12 #var #java 14 #java 13 #java 15 #verbosity