I have rdd like this
but I want to get whole rdd as a one element
collect is not recommended exactly for this reason. collect transfers the entire data of the RDD collection to the driver application (which runs on a single machine) which is not possible for large dataset since you would get out of memory exception. so if you really want this you take the route of
mkString and avoid using it on large RDDs.