Problems with vectors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • japuentem
    New Member
    • Jun 2007
    • 31

    Problems with vectors

    I have an application that receive some vectors inside one main vector. The user set the information to the arrays

    vector1 {a, b}
    vector2 {1, 2}
    vector3 {x, y}
    vector4 {20,21}
    vector5 {s,t}
    mainVector {vector1,vector 2,vector3,vecto r4,vector5}

    and i print the information on the screen as follows

    a 1 x 20 s
    b 2 y 21 t

    my problem is when the user set just one value in the vector, for example the user don't set the x value:

    a 1 20 s
    b 2 y 21 t

    this throw me an ArrayIndexOutOf BoundsException

    is there something that i can do, or i should use arrays instead vectors
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by japuentem
    I have an application that receive some vectors inside one main vector. The user set the information to the arrays

    vector1 {a, b}
    vector2 {1, 2}
    vector3 {x, y}
    vector4 {20,21}
    vector5 {s,t}
    mainVector {vector1,vector 2,vector3,vecto r4,vector5}

    and i print the information on the screen as follows

    a 1 x 20 s
    b 2 y 21 t

    my problem is when the user set just one value in the vector, for example the user don't set the x value:

    a 1 20 s
    b 2 y 21 t

    this throw me an ArrayIndexOutOf BoundsException

    is there something that i can do, or i should use arrays instead vectors
    Nope, you should use classes and objects instead: use a class that can store
    (using your notation) { a, b }, { 1, 2, }, { x, y }, { 20, 21 } and { s, t } instead. That
    way you have kept the coupling of those pairs encapsulated in one single object
    instead. Using arrays (or Lists for that matter) for every single datum item is so
    outdated Fortranesque.

    kind regards,

    Jos

    Comment

    Working...