+ 2

Why We Use Join Method In Java .?

Please help me to figure out..

5th Jan 2017, 3:15 PM
Sohail Ansari
Sohail Ansari - avatar
4 Respuestas
+ 5
Yes, it basically converts arrays to strings (and then to "P P A P" fruits)… ^_^
5th Jan 2017, 3:48 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
If you have an array, say, arr = ["Apple", "pen"], array.join(" ") will give you "Apple pen". ["Apple", "pen", "pineapple", "pen"].join("-") will result in "Apple-pen-pineapple-pen". The join() method is used when certain methods, like sort(), which is only available for arrays, cannot be used on strings.
5th Jan 2017, 3:45 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar
+ 2
thanks ;_; the example is awesome 🐸
5th Jan 2017, 3:47 PM
Sohail Ansari
Sohail Ansari - avatar
+ 2
If you have a string, and you want to let's say sort the characters, you can split the string with .split("") into arrays and use those methods only available for arrays.
5th Jan 2017, 3:49 PM
David Sebastian Keshvi Illiakis
David Sebastian Keshvi Illiakis - avatar