Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
AbstractSequentialList hashCode() method in Java with Example
Next article icon

AbstractSequentialList lastIndexOf() method in Java with Example

Last Updated : 24 Dec, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The lastIndexOf() method of java.util.AbstractSequentialList class is used to return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index. Syntax:
public int lastIndexOf(Object o)
Parameters: This method takes Object o as parameter which is the element to search for. Return Value: This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. Exception: This method throws:
  • ClassCastException: if the type of the specified element is incompatible with this list.
  • NullPointerException: if the specified element is null and this list does not permit null elements.
Below are the examples to illustrate the lastIndexOf() method. Example 1: Java
// Java program to demonstrate lastIndexOf() // method for AbstractSequentialList  import java.util.*;  public class GFG {     public static void main(String[] args)     {          // Creating object of AbstractSequentialList         AbstractSequentialList<Integer>             arrlist1 = new LinkedList<Integer>();          // Populating arrlist1         arrlist1.add(10);         arrlist1.add(20);         arrlist1.add(30);         arrlist1.add(40);         arrlist1.add(50);          // print arrlist1         System.out.println("AbstractSequentialList: "                            + arrlist1);          // getting the index of element 30         // using lastIndexOf() method         int index = arrlist1.lastIndexOf(30);          // print the index         System.out.println("Last Index of 30: "                            + index);     } } 
Output:
  AbstractSequentialList: [10, 20, 30, 40, 50]  Last Index of 30: 2  
Example 2: Java
// Java program to demonstrate lastIndexOf() // method for AbstractSequentialList  import java.util.*;  public class GFG1 {     public static void main(String[] args)     {         // Creating object of AbstractSequentialList         AbstractSequentialList<Integer>             arrlist1 = new LinkedList<Integer>();          // Populating arrlist1         arrlist1.add(10);         arrlist1.add(20);         arrlist1.add(30);         arrlist1.add(40);         arrlist1.add(50);          // print arrlist1         System.out.println("LinkedListlist: "                            + arrlist1);          // getting the index of element 100         // using lastIndexOf() method         int index = arrlist1.lastIndexOf(100);          // print the index         System.out.println("Last Index of 100: "                            + index);     } } 
Output:
  LinkedListlist: [10, 20, 30, 40, 50]  Last Index of 100: -1  

Next Article
AbstractSequentialList hashCode() method in Java with Example

C

code_r
Improve
Article Tags :
  • Java
  • Java-Collections
  • Java - util package
  • Java-Functions
  • java-AbstractSequentialList
Practice Tags :
  • Java
  • Java-Collections

Similar Reads

    AbstractSequentialList in Java with Examples
    The AbstractSequentialList class in Java is a part of the Java Collection Framework and implements the Collection interface and the AbstractCollection class. This class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "s
    7 min read
    AbstractSequentialList size() method in Java with Example
    The size() method of AbstractSequentialList in Java is used to get the size for this instance of the AbstractSequentialList. It returns an integer value which is the size for this instance of the AbstractSequentialList. Syntax: public int size() Parameters: This method does not accepts any parameter
    2 min read
    AbstractSequentialList conatinsAll() method in Java with Example
    The containsAll() method of Java AbstractSequentialList is used to check whether two Collections contain the same elements or not. It takes one collection as a parameter and returns True if all of the elements of this collection is present in the other collection. Syntax: public boolean containsAll(
    2 min read
    AbstractSequentialList lastIndexOf() method in Java with Example
    The lastIndexOf() method of java.util.AbstractSequentialList class is used to return the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i)
    2 min read
    AbstractSequentialList hashCode() method in Java with Example
    The hashCode() method of AbstractSequentialList in Java is used to get the hashCode value for this instance of the AbstractSequentialList. It returns an integer value which is the hashCode value for this instance of the AbstractSequentialList. Syntax: public int hashCode() Parameters: This function
    2 min read
    AbstractSequentialList retainAll() method in Java with Example
    The retainAll() method of java.util.AbstractSequentialList class is used to retain from this list all of its elements that are contained in the specified collection. Syntax: public boolean retainAll(Collection c) Parameters: This method takes collection c as a parameter containing elements to be ret
    3 min read
    AbstractSequentialList subList() method in Java with Example
    The subList() method of AbstractSequentialList in Java is used to get a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned list is empty.) The returned list is backed by this list, so non-structural c
    2 min read
    AbstractSequentialList toArray() method in Java with Example
    The toArray() method of Java AbstractSequentialList is used to form an array of the same elements as that of the AbstractSequentialList. Basically, it copies all the element from a AbstractSequentialList to a new array. Syntax: Object[] arr = AbstractSequentialList.toArray() Parameters: The method d
    2 min read
    AbstractSequentialList toArray(T[]) method in Java with Example
    The toArray(arr[]) method of AbstractSequentialList class in Java is used to form an array of the same elements as that of the AbstractSequentialList. It returns an array containing all of the elements in this AbstractSequentialList in the correct order; the run-time type of the returned array is th
    4 min read
    AbstractSequentialList contains() method in Java with Example
    The contains() method of Java AbstractSequentialList is used to check whether an element is present in a Collection or not. It takes the element as a parameter and returns True if the element is present in the collection. Syntax: public boolean contains(Object element) Parameters: The parameter elem
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences