< prev index next >

src/java.base/share/classes/java/util/Stack.java

Print this page




 120      * occurrence nearest the top of the stack; the topmost item on the
 121      * stack is considered to be at distance {@code 1}. The {@code equals}
 122      * method is used to compare {@code o} to the
 123      * items in this stack.
 124      *
 125      * @param   o   the desired object.
 126      * @return  the 1-based position from the top of the stack where
 127      *          the object is located; the return value {@code -1}
 128      *          indicates that the object is not on the stack.
 129      */
 130     public synchronized int search(Object o) {
 131         int i = lastIndexOf(o);
 132 
 133         if (i >= 0) {
 134             return size() - i;
 135         }
 136         return -1;
 137     }
 138 
 139     /** use serialVersionUID from JDK 1.0.2 for interoperability */

 140     private static final long serialVersionUID = 1224463164541339165L;
 141 }


 120      * occurrence nearest the top of the stack; the topmost item on the
 121      * stack is considered to be at distance {@code 1}. The {@code equals}
 122      * method is used to compare {@code o} to the
 123      * items in this stack.
 124      *
 125      * @param   o   the desired object.
 126      * @return  the 1-based position from the top of the stack where
 127      *          the object is located; the return value {@code -1}
 128      *          indicates that the object is not on the stack.
 129      */
 130     public synchronized int search(Object o) {
 131         int i = lastIndexOf(o);
 132 
 133         if (i >= 0) {
 134             return size() - i;
 135         }
 136         return -1;
 137     }
 138 
 139     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 140     @java.io.Serial
 141     private static final long serialVersionUID = 1224463164541339165L;
 142 }
< prev index next >