Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Javascript (https://www.askmehelpdesk.com/forumdisplay.php?f=452)
-   -   Index out of bound (https://www.askmehelpdesk.com/showthread.php?t=810216)

  • Apr 7, 2015, 11:41 AM
    raidmax
    Index out of bound
    Hi I'm getting index out of bound with the code below but I cannot find exactly what is causing the error.can anybody help.tnks

    import java.util.*;


    class allshortinVector
    {
    public static void main(String[] args)
    {
    Vector<String> v=new Vector();


    v.addElement("test");
    v.addElement("hello");
    v.addElement("JAVA");
    v.addElement("Program");


    Vector<String> v2=new Vector();


    for(int I=0 ; I < v.size() ; I++)
    {
    if( v.elementAt(I).length() < v.elementAt(I + 1).length() ) // checking which element is the longest
    {
    v2.addElement(v.elementAt(I)); // store them in vector v2
    }
    }
    for(String z : v2)
    System.out.println(z);
    }
    }

  • All times are GMT -7. The time now is 09:49 PM.