class A{
Vector<String> s = new Vector<String>();
}
public class Vec {
public static void main(String[] args) {
A a = new A();
a.s.add("String1");
a.s.add("String2");
a.s.add("String3");
a.s.add("String4");
a.s.add("String5");
Vector<A> vecA = new Vector<A>();
vecA.add(a);
System.out.println("Size of vector is "+vecA.size()); // here i am getting size one
a.s.clear();
a.s.add("String6");
a.s.add("String7");
a.s.add("String8");
a.s.add("String9");
a.s.add("String10");
vecA.add(a);
System.out.println("Size of vector is "+vecA.size()); // here i am getting size 2
for(int i=0;i<vecA.size();i++)
{
System.out.println(vecA.get(i).s.get(0));
System.out.println(vecA.get(i).s.get(1));
System.out.println(vecA.get(i).s.get(2));
System.out.println(vecA.get(i).s.get(3));
System.out.println(vecA.get(i).s.get(4));
}
}
}
output :
size of vector is 1
size of vector is 2
String6
String7
String8
String9
String10
String6
String7
String8
String9
String10
Here i am facing problem.
in vecA at index-0 i stored String1,String2,String3,String4,String5
and at index-1 i stored String6,String7,String8,String9,String10
but in output at index-0 and index-1 i am getting same output as in index-1.
please tell me where the fault is ?
Thank,
pavan.
narlapavan 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.