Latest web development tutorials

Contoh Java - Daftar beredar elemen gerakan

Contoh Java Contoh Java

Contoh berikut menunjukkan bagaimana menggunakan Koleksi class rotate () loop untuk memindahkan elemen dengan parameter kedua menentukan posisi awal dari:

/*
 author by w3cschool.cc
 Main.java
 */

import java.util.*;

public class Main {
   public static void main(String[] args) {
      List list = Arrays.asList("one Two three Four five six".split(" "));
      System.out.println("List :"+list);
      Collections.rotate(list, 3);
      System.out.println("rotate: " + list);
   }
}

Kode di atas dijalankan output:

List :[one, Two, three, Four, five, six]
rotate: [Four, five, six, one, Two, three]

Contoh Java Contoh Java