View RSS Feed

Recent Blogs Posts

  1. Rotating Elements In a List using Collections.rotate Method

    by , 11-08-2011 at 07:22 PM (My Java Tips)
    Collections have very useful methods. Let us see how to rotate objects in a given list. The method "rotate" has two inputs, a list and a distance parameter which defines rotation distance. The distance can be positive, negative or zero. Objects in the list will be rotated by the specified parameter. Let us take an example to rotate objects of Car class.

    For example, suppose list comprises [t, a, n, k, s]. After invoking

    Collections.rotate(list, 1) ...