How to get the index of the first occurrence of a specific item in a LinkedList with Java

1 Answer

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

 



answered Feb 27, 2024 by avibootz

Related questions

1 answer 158 views
2 answers 210 views
1 answer 171 views
1 answer 126 views
...