Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

creating names for vectors

 
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));

}
 
Ranch Hand
Posts: 2410
  • 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: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can create an array of object references.
 
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.
 
Your buns are mine! But you can have this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic