Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

list in java

public static void main(String[] args)
    {
        List<Integer> l1 = new ArrayList<Integer>();
  
        l1.add(1, 2);    // Custom inputs
    
        System.out.println(l1); // Print the elements inside the object
   
        l1.add(1);
        l1.add(2);
        l1.add(3);
  
        // Will add list l2(ASSUMING THAT l2 is ANOTHER LIST) from 1 index
        l1.addAll(1, l2);
        l1.remove(1);      
        System.out.println(l1.get(3)); // using get() method
        l1.set(0, 5); // Replace 0th element with 5
    }
Source by openclassrooms.com #
 
PREVIOUS NEXT
Tagged: #list #java
ADD COMMENT
Topic
Name
2+8 =