Hi I'm trying to sort a matrix by a column in alphabetical order
I tried with this: It's just a bubblesort that I tried out var artists2=Array.ofDimString// Artist Name,Year
var compare=0
var aux2=""
for(i <- 0 to 99){
for(j <- 0 to 993){
compare = artists(j)(0).compareTo(artists(j+1)(0))
if (compare < 0) { //a is smaller b>a
aux2=artists(j)(0)
artists(j)(0)=artists(j+1)(0)
artists(j+1)(0)=aux2
aux2=artists(j)(1)
artists(j)(1)=artists(j+1)(1)
artists(j+1)(1)=aux2
}
}
}
println(artists.map(_.mkString(" ")).mkString("\n"))
But I get a null pointer Exception I know this is not suposed to work with string so if you have any suggestions please let me know my matrix has tu colums artists and years I want to sort it out by the artists column but still conserve each artist year