Get item in the list in Scala?

How in the world do you get just an element at index i from the List in scala?

I tried get(i), and [i] – nothing works. Googling only returns how to “find” an element in the list. But I already know the index of the element!

Here is the code that does not compile:

def buildTree(data: List[Data2D]):Node ={
  if(data.length == 1){
      var point:Data2D = data[0]  //Nope - does not work
       
  }
  return null
}

Looking at the List api does not help, as my eyes just cross.

4 Answers
4

Leave a Comment