Create a single line in Java that will output the reversed string to the console.
Answer :- In javascript, If we want to reverse a string , it will take a few steps of code because of the proper syntax and use. But wit the ES6 new features , we can use the reverse string function and impliment it by using only a single line .
Code
:--
const reverseString = str => str.split(' ').reverse( ).join(' ');
reverseString( ' Welcome ');
Explaintion :- In the above code , first we used split function to split the letters seperately sso that "Welcome" can be converted to 'w','e','l','c','o','m','e' . After it the reverse function is used which will reverse the occurance of alphabets , Then we finally used join to form a word of the reversed string .
Ex:- String "Welcome" will be reversed to "emoclew" .
Get Answers For Free
Most questions answered within 1 hours.