Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating names for vectors

 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to make an unlimited number of vectors and need to call then something to keep track of them is there a way to do this. I have code that I want to avoid

if(POI > 2 )
{
Vector POI3 = new Vector();
System.out.println("Enter POI one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
POI3.addElement(new Integer(p));
}
Enumeration EnPOI3 = POI3.elements();
while(EnPOI3.hasMoreElements())
System.out.print(EnPOI3.nextElement() +", ");
System.out.println();
System.out.println("Enter coordinates");
String POI3co = br.readLine();
}
if(POI > 3 )
{
Vector POI4 = new Vector();
System.out.println("Enter POI one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
POI4.addElement(new Integer(p));
}
Enumeration EnPOI4 = POI4.elements();
while(EnPOI4.hasMoreElements())
System.out.print(EnPOI4.nextElement() +", ");
System.out.println();
System.out.println("Enter coordinates");
String POI4co = br.readLine();
}
Vector v1 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 0; i < len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v1.addElement(new Integer(p));

}
if(number > 1 )
{
Vector v2 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v2.addElement(new Integer(p));
}
}
if(number > 2 )
{
Vector v3 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v3.addElement(new Integer(p));
}
}
if(number > 3 )
{
Vector v4 = new Vector();
System.out.println("Enter vector one number at a time DO NOT enter the comma's ");
for(int i = 1; i <= len; i++)
{
String input = br.readLine();
int p = Integer.parseInt(input);
v4.addElement(new Integer(p));

}
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about an array of Vectors?
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you have that. I never tried. Thanks
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can create an array of object references.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given that you want an unlimited number, why not a Vector of Vectors, or an ArrayList of ArrayLists?
 
Donna Bachner
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you everyone I got it working.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic