There is a List. It has any number of lines. I want to copy from this list to the other 10 lines. That is, first the first 10 and then the second 10 to the end. Tell me how to implement. Thank you in advance

    1 answer 1

    public class JavaApplication66 { /** * @param args the command line arguments */ public static void main(String[] args) { //Бписок с ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ³ΠΎ Π±ΡƒΠ΄ΡƒΡ‚ ΠΊΠΎΠΏΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ Π΄Π°Π½Π½Ρ‹Π΅ List<String> lst = new ArrayList<>(); //ЗаполняСм список значСниями for (int i = 0; i < 35; i++) { lst.add(""+i); } //ΠΊΠΎΠΏΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ подсписок List<String> lst1 = lst.subList(0, 10); //Π²Ρ‚ΠΎΡ€ΠΎΠΉ подсписок List<String> lst2 = lst.subList(10, 20); //Ρ‚Ρ€Π΅Ρ‚ΠΈΠΉ подсписок List<String> lst3 = lst.subList(20, 30); //провСряСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ for(String st: lst1){ System.out.println(st); } System.out.println("-/-/-/-"); for(String st: lst2){ System.out.println(st); } System.out.println("-/-/-/-"); for(String st: lst3){ System.out.println(st); } } } 

    Copying to sublists can be put into a method or loop, but you should already do this, since you better understand how it should look.

    • one
      thank. With a cycle already I will understand. - Stas