6. 1 Other Collections.pdf - Other Collections Other...

  • No School
  • AA 1
  • 13

This preview shows page 1 - 6 out of 13 pages.

Other Collections
Image of page 1
Other Sequences We have seen that lists are linear : Access to the first element is much faster than access to the middle or end of a list. The Scala library also defines an alternative sequence implementation, Vector . This one has more evenly balanced access patterns than List .
Image of page 2
Operations on Vectors Vectors are created analogously to lists: val nums = Vector(1, 2, 3, -88) val people = Vector( ”Bob” , ”James” , ”Peter” ) They support the same operations as lists, with the exception of :: Instead of x :: xs , there is x +: xs Create a new vector with leading element x , followed by all elements of xs . xs :+ x Create a new vector with trailing element x , preceded by all elements of xs . (Note that the : always points to the sequence.)
Image of page 3
Collection Hierarchy A common base class of List and Vector is Seq , the class of all sequences . Seq itself is a subclass of Iterable .
Image of page 4
Arrays and Strings Arrays and Strings support the same operations as Seq and can implicitly be converted to sequences where needed.
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 13 pages?

  • Fall '19

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors