Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
How can I get the last value of arrayList (e.g. I dont know the last index of the ArrayList)? Thanks.
I am new to java. I had a doubt. class ArrTest{ public static void main(String args[]) { int i = 0; int[] a = {3,6}; a[i] = i = 9; System.out.println(i + " " + a[0] + " " + a[1]); // 9 9 6 } } Thanks in advance
Imagine I have the methods: public static void funcA() {...} public static void funcB() { byteBuffer.wrap(someByteArray, 0, someByteArra.length); } IN JAVA API: public static ByteBuffer wrap(byte[]array, int offset, int length) { try { return new HeapByteBuffer(array, offset, length); } catch (IllegalArgumentException x) { throw new IndexOutOfBoundsException();...
I'm trying to manually throw an index out of bounds exception for an array. I know that to throw a regular exception, I can do something like: if(x>array.length){ throw new Exception("Bad choice!"); } But how can I do the index out of bounds exception? Thanks
I wrote this little function just for practice, but an exception ("String index out of range: 29") is thrown and I don't know why... (I know this isn't the best way to write this function and can I use regular expressions.) This is the code: public String retString(String x) { int j=0; int i=0; StringBuffer y = new StringBuffer(x); try { while ( y.charAt(i) != '\0' ) ...
I'm really confused: I'm simply trying to add the names of each object in an ArrayList to another ArrayList. for (int i = 0; i < availableParts.size(); i++) { for (int j = 0; j < namesOfIngredients.size(); j++){ if (availableParts.get(i).getName() != namesOfParts.get(j)){ namesOfParts.add(availableParts.get(i).getName()); } }//middle if statement ma...
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList { synchronized public Boid GetBoid( int idx_ ) throws ArrayIndexOutOfBoundsException { if( idx_ < super.size() && idx_ >= 0 ) { return (Boid) super.get(idx_); } else { throw new ArrayIndexOutOfBoundsException(); } } synchronized pub...
 /*
  * Copyright 1995-1997 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package java.lang;

Thrown to indicate that an index of some sort (such as to an array, to a string, or to a vector) is out of range.

Applications can subclass this class to indicate similar exceptions.

Author(s):
Frank Yellin
Since:
JDK1.0
public
class IndexOutOfBoundsException extends RuntimeException {
    
Constructs an IndexOutOfBoundsException with no detail message.
    public IndexOutOfBoundsException() {
        super();
    }

    
Constructs an IndexOutOfBoundsException with the specified detail message.

Parameters:
s the detail message.
    public IndexOutOfBoundsException(String s) {
        super(s);
    }
New to GrepCode? Check out our FAQ X