Converting Arrays into CSVs:
Method 1: Using toString() function
The toString() method converts an array into a String and returns the result. The returned string will separate the elements in the array with commas.
Method 2: Using valueof() function
The valueOf() method returns the primitive value of an array. Again the returned string will separate the elements in the array with commas.
There is no difference in toString() and valueOf(). Even if we try with different data types like number, strings etc it would give the same result.
Method 3: using join() function
The join() method joins the elements of an array into a string and returns the string.
By default, the join() method returns a comma (, ) separated value of the array. But you can give an argument to join() method and specify the separator. For example:
Converting CSVs into Arrays: Using split() function
Now let us see how we can convert a string with commas separated values into an Array.
geeks 4 geeks
Thus split() method of String comes handy for this. It is used to split a string into an array of substrings and returns the new array. The split() method does not change the original string.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.