How To Convert integer, double, short, long, byte, array into a String Using the valueOf() Method

preview_player
Показать описание
How To Convert integer, double, short, long, byte, array into a String Using the valueOf() Method

In this video, we will talk about the Java String valueOf() method and I will show you how we can use this method to convert data types like the integer, float, double, Boolean into String data type. One key point to note is that this method returns a String value.
So, now let me explain further, how to use this method by giving you examples

1. In the first example, I will show you how to convert an Integer into a String

int myNumber = 20;

We will then use a String variable to store the value being returned whenever the valueOf() method is going to be evaluated

When we run this program the output in our console will be : 2020
The system has joined the String value store in variable return_value (which is the String representation of the integer variable myNumber) with the constant value 20.

2. In the second example, we will convert floating point number in to a String

float decimal_number = 9.5 ;

When we run this, the console will show: 9.520
Here 9.5 is taken has a String, because of the conversion that happened on the previous line.

3. In the third example, we will convert an Array of characters into a String

char alphabet[] = { ‘A’ , ‘B’ , ‘C’ , ‘D’ , ‘E’ };

The output of this program will be: ABCDE
This String showing in the console represents the String representation of the array of characters alphabet.

We will stop here, but note that the conversions into String type can be done for all the other primitive data type.

So, guys, thanks for viewing, I hope video was informative and please do not forget to support this channel by liking this video and also by subscribing to this channel.

Let’s meet in the next video. Cheers !!!!!

#codingriver
#java
#programming
Рекомендации по теме