You can use sortBy:
rdd.sortBy(r => (r._3, r._2(0)), false)
In the above, r._3 stands for the last column, r._2(0) for the first element of the second column (which is an array), and false specifies that the order should be descending. Bear in mind though that sorting is an expensive operation due to shuffling.
Update
Here's a reproducible example if we assume you start with a pair rdd:
/// Generate data val rdd = sc.parallelize(Seq(("ABC","G4"),("ABC","G3"), ("ABC","G1"),("FFF","G5"), ("FFF","G4"),("FFF","G3"), ("CDE","G5"),("CDE","G4"), ("CDE","G3"),("CDE","G2"), ("XYZ","G4"),("XYZ","G3"))) /// Put values in a list and calculate its size val rdd_new = rdd.groupByKey.mapValues(_.toList).map(x => (x._1, x._2, x._2.size)) /// Now this works rdd_new.sortBy(r => (r._3, r._2(0)), false).collect() /// Array[(String, List[String], Int)] = Array((CDE,List(G5, G4, G3, G2),4), (FFF,List(G5, G4, G3),3), (ABC,List(G4, G3, G1),3), (XYZ,List(G4, G3),2))