Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java.lang.ArrayIndexOutOfBoundsException

import java.util.Random;
public class demo{
  public static void main(String[]args){
    Random rand=new Random();
    int array[]=new int[10];
    for(int i=0;i<array.length;i++){
      array[i]=rand.nextInt(100);//random between 0 and 100
    }
    System.out.println(array[array.length]);// error java.lang.ArrayIndexOutOfBoundsException
    // because index start 0 and end array.length
  }

}
Comment

java.lang.arrayindexoutofboundsexception: -1

check the code if it is accesing the element at negative index
Comment

ArrayIndexOutOfBoundsException

class AccessArrayOutsie
{
    public static void main (String[] args)
    {
        int[] array = new int[3];
        array[0] = 3;
        array[1] = 5;
  	array[2] = 6;
 
        for (int i = 0; i <= array.length; i++)
            System.out.println(array[i]);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: what is java steam 
Java :: Java Enum ordinal() 
Java :: Java array repeating 
Java :: why is java so verbose 
Java :: client missing intents 
Java :: why cant we have primitive types in generixs 
Java :: como limpar a tela do consola no java 
Java :: selenium firefox to foreground -python java 
Java :: how to create simple java bean class for login page in eclipse 
Sql :: codeigniter print last sql query 
Sql :: mysql last 7 days including today 
Sql :: sql server reset id 
Sql :: create database mysql utf8 
Sql :: forgot my mysql password mac 
Sql :: check connections to database postgres 
Sql :: postgresql get table names 
Sql :: mysql list databases 
Sql :: get all tables postgres 
Sql :: SQLSTATE[HY000] [1049] Unknown database 
Sql :: mysql add boolean column 
Sql :: sql script get all stored procedures from database 
Sql :: show indexes in mql 
Sql :: Find all tables containing column with specified name - MS SQL Server 
Sql :: mssql current date 
Sql :: get current month mysql 
Sql :: select password from user mysql 
Sql :: append column sql 
Sql :: how to get current mysql version 
Sql :: sql exclude duplicates and find even id 
Sql :: oracle next run dates 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =