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
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.
- onethank. With a cycle already I will understand. - Stas
|