Saturday 27 July 2019

JAVA Tutorial | How To Convert Array Into String Without Loops | Quickes...





class array_to_string

{

public static void main(String ar[])

{

String output="";

String arr[]={"Captain","America","lifts","the","HAMMER"};

/*

for(int i=0;i<arr.length;i++)

{

output = output + arr[i] + ",";

}

*/

output=String.join(" ",arr);

System.out.println(output);

}

}


Subscribe my Channel:-
http://www.youtube.com/user/SanketRooney?sub_confirmation=1

Facebook Page:-
https://www.facebook.com/UnpossibleNS

Twitter Account:-
https://twitter.com/UnpossiblePOG

Blog :-
https://unpossiblepog.blogspot.in/

Hello guys, this is unpossible pog here.
Today, I shall show you the easiest and convenient way to convert array into string in JAVA.
So, generally we use loops to convert but main problem is that it will take more time to execute for large array.
And secondly, even if we do that, we see some unwanted characters either at the begenning or ending of string.
You can see that, the COMMA is bothering me.
So, java has a function called join with two arguments. 1st is the glue and second will be the array.
With that, the values are automatically connected by glue and no extra COMMAS.
The code is in the description.
Thank you for watching, dont forget to like share and subscribe.

The Grishneshwar Temple