Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,855 questions

51,776 answers

573 users

How to to create a sub list from an ArrayList in Java

2 Answers

0 votes
import java.util.ArrayList;
import java.util.List;
  
public class MyClass {
    public static void main(String args[]) {
        ArrayList arrList = new ArrayList();
    
        arrList.add("Java");
        arrList.add("C#");
        arrList.add("C++");
        arrList.add("PHP");
        arrList.add("JavaScript");
        arrList.add("C");
        arrList.add("Swift");
         
        List sublist = arrList.subList(1, 4);
        
        for (int i = 0; i < sublist.size(); i++) 
            System.out.println(sublist.get(i));
    }
}
    
    
    
    
/*
run:
    
C#
C++
PHP
 
*/

 



answered Sep 21, 2016 by avibootz
edited Feb 20, 2024 by avibootz
0 votes
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
   
public class MyClass {
    public static void main(String args[]) {
        ArrayList al = new ArrayList(Arrays.asList("c#", "c++", "c", "java", "go", "python"));
    
        List<String> sublist = al.subList(1, 4);
          
        System.out.println(sublist); 
           
        for (String str : sublist) {
            System.out.println(str);
        }  
    }
}
     
     
     
     
/*
run:
     
[c++, c, java]
c++
c
java
  
*/

 



answered Feb 20, 2024 by avibootz

Related questions

3 answers 203 views
1 answer 142 views
1 answer 200 views
1 answer 137 views
137 views asked Jun 28, 2020 by avibootz
1 answer 128 views
2 answers 162 views
...