How to get the first element from LinkedList in Java

2 Answers

0 votes
import java.util.LinkedList; 
 
public class MyClass {
    public static void main(String args[]) { 
        LinkedList<String> ll = new LinkedList<String>(); 
  
        ll.add("c++"); 
        ll.add("java"); 
        ll.add("c#"); 
        ll.add("c"); 
        ll.add("php"); 
        ll.add("python"); 
  
        System.out.println(ll.pop()); 
    }
}
 
 
 
/*
run:
 
c++
 
*/

 



answered Apr 18, 2020 by avibootz
0 votes
import java.util.LinkedList;
 
public class MyClass {
    public static void main(String args[]) {
        LinkedList<String> ll = new LinkedList<String>(); 
   
        ll.add("c++"); 
        ll.add("java"); 
        ll.add("c#"); 
        ll.add("c"); 
        ll.add("php"); 
        ll.add("python"); 
  
        System.out.println(ll.getFirst());
    }
}
     
     
     
     
/*
run:
     
c++
     
*/

 



answered Apr 16, 2024 by avibootz

Related questions

2 answers 255 views
1 answer 188 views
1 answer 234 views
1 answer 179 views
1 answer 144 views
2 answers 216 views
...