Vector.contains()

Hi,
I have a question about Vector.contains(). The documentation for Vector.contains() says:
Tests if the specified object is a component in this vector.
Returns true if and only if the specified object is the same as a component in this vector, as determined by the equals method; false otherwise.
Since Vector.contains() takes an Object as a parameter and Object.equals() takes and Object has a parameter I assumed that Vector.contains(a) would return true if at least one object in the Vector returned true for .equals(a). But it seems to me (after some pretty simple testing) that the two objects HAVE to be of the same class, yet it does not actually say this in the documentation.
Can someone explain to me why this is the case, or tell me that I am somehow doing somthing wrong? I dont have somple simple test code but I dont want to post it here intitiall as I might scare people off :p. I spend hours debugging this simple problem.. grr :S.
Anyway,
Thanks in advance.

Thanks for your quick replies!!
Do you not think this is a given? How is it possible for two objects to be the same if they are different classes?I'm not saying that its not logical, its just that the documentation doest actually specify that the classes have to be of the same type to be found. You might, for example, want to search a list of 'Person' objects for a person with a particular name. In this case (where a is defined as Vector<Person>), you might want to call a.contains("Barry"). Based on the documentation I would have thought this to be possible, as long as the Person.equals() function handled it correctly.
Here is my test code:
import java.util.*;
public class Test
        static class MyClass
                String myValue;
                public MyClass(String val)
                        myValue = val;
                public boolean equals(Object o)
                        return o.toString().equals(myValue);
                public String toString()
                        return myValue;
        public static void main(String[] args)
                Vector<MyClass> v = new Vector<MyClass>();
                v.add(new MyClass("TEST1"));
                v.add(new MyClass("TEST2"));
                if (v.contains("TEST2"))
                        System.out.println("Contains!");
                else
                        System.out.println("Does not contain!");
}In this case "Does not contain!" could be printed out. If i change the line
if (v.contains("TEST2"))to
if (v.contains(new MyClass("TEST2")))then "Contains!" is printed out. I would have thought both should work :S.
Thanks again
- Robert.

Similar Messages

  • Vectors: contains() inconsistency with Object equals()

    Hi,
    I have a problem with using Vector contains() on my own classes.
    I have a class TermDetails, on which I have overloaded the equals() method:
         public boolean equals(Object other) {
              try {
                   TermDetails otherTerm = (TermDetails) other;
                   return (term.equals(otherTerm.term));
              catch (Exception e) {
                   try {
                        String otherTermString = (String) other;
                        return (term.equals(otherTermString));
                   catch (Exception f) {
                        System.out.println("Can't convert Object to TermDetails or String");
                        System.out.println(f.getMessage());
                        return(false);
         public boolean equals(String otherTermString) {
              return(term.equals(otherTermString));
    The Vector.contains() should then use one of these equals methods to return correctly, but doesn't use either of them... any ideas why not?
    (I've tried adding some console output in the equals methods, just to prove if they get called or not. They don't.)
    Thanks in advance!
    Ed

    This won't work. It only tests whether the two objects are of the same class. In general, you need to test a number of things:
    1) if obj == this, return true
    2) if obj == null, return false
    3) if obj.getClass() != this.getClass() return false
    (Note: You don't need getClass().getName(). Also, there are times when the classes don't have to match, but it's sufficient that obj and this implement a particular interface--Map for instance).
    4) if all relevant corresponding fields of obj and this are equal, return true, else false.
    That's just a high level run-down, and you should definitely look at the book that schapel mentioned.
    Also, this probably won't affect Vector.contains, but make sure that when you override equals, you also override hashCode. The rule is that if a.equals(b) returns true, then a.hashCode() must return the same value as b.hashCode(). Basically any field that is used in computing hashCode must also be used in equals.
    Note that the converse is not true. That is two objects with the same hashCode don't have to be equal.
    For instance, if you've got a class that represents contact info, the hashCode could use only the phoneNumber field. hashCode will then be fast to compute, will probably have a good distribution (some distinct people's contact info could have the same phone number, but there won't be a large overlap), and then you use phone number plus the rest of the fields (address, etc.) for equals.
    Here's an example that shows that equals will work if
    written correctly
    import java.util.Vector;
    public class testEquals {
    public static void main(String args[]) {
    Vector testVector = new Vector();
    testVector.add(new A());
    testVector.add(new B());
    System.out.println("A == A? " +
    + testVector.contains(new A()));
    System.out.println("B == B? " +
    + testVector.contains(new B()));
    class A {
    public boolean equals(Object object) {
    if (getClass().getName() ==
    = object.getClass().getName()) {
    System.out.println("A == A");
    return true;
    } else {
    return false;
    class B {
    public boolean equals(Object object) {
    if (getClass().getName() ==
    = object.getClass().getName()) {
    System.out.println("B == B");
    return true;
    } else {
    return false;

  • Problem with Vector.contains

    Hello,
    I wrote this code but it doens't work; but it should
    public class Word {
         public Word(String v) { _value = new String (v); }
         public Word() { _value ="";  }
         String _value = null;
         public boolean equals(Object obj) {
              if(this == obj)
                   return true;
              if((obj == null) || (obj.getClass() != this.getClass()))
                   return false;
              Word word = (Word)obj;
              return _value != null && _value.equals(word._value);                         
         public int hashCode() {
              int hash = 7;
              //hash = 31 * hash + num;
              hash = 31 * hash + (null == _value ? 0 : _value.hashCode());
              return hash;
    public class MyDictionary {     
         private Vector<Word> _words = new Vector<Word>();     
         Vector<Word> getWord() { return _words; }
    //other class
    MyDictionary dic = new MyDictionary();
                                    List< String > _testDoc = new ArrayList< String > ();
                                    //fill _testDoc
                                    Iterator<String> iter = _testDoc.iterator(); /
                                    for (int i=0; iter.hasNext(); i++ ) {
                               if ( dic.getWord().contains( new Word( iter.next() ) )) {
                                System.out.println("......................................");
                                     }I assure you (because I saw it) that _testDoc has words contained in dic; instes that if is never executed; probably I'm missing something simple....
    thanks
    Edited by: mickey0 on Aug 17, 2009 10:45 AM

    mickey0 wrote:
    Hello,
    I wrote this code but it doens't work; but it shouldIf it "doesn't work", then it's not supposed to work.
    mickey0 wrote:
    I assure you (because I saw it) that _testDoc has words contained in dic; instes that if is never executed; Can you post an SSCCE that shows this?
    mickey0 wrote:
    probably I'm missing something simple....This remark contradicts your earlier claim that it should work.

  • Vector contains and Integer

    Hello
    So far I tried to use a Vector to store different integers. I wrap them in an Integer object and add them to the Vector.
    Since the user can select (from a JTree) multiple nodes and even the same node by clicking it again, I have to check if the ID is already stored in the Vector. But my implementation does not work - the contains method seems not to work for me. I guess I have a wrong understanding.
    What happens is that if I click let's say on Node X with the ID of 5, the ID get's stored, but if I click on any other node contains returns true and the already stored node gets removed.
    I'd be glad for any advise. This is the snippet:
                category_id = category.getCategory_id();           
                module_id = category.getModule_id();
                create = category.getCREAT();
                Integer categoryInt = new Integer(category_id);
                System.out.println("Value changed: "+category_id);
                if(categories.contains(categoryInt))
                     categories.remove(categoryInt);
                else
                     categories.add(categoryInt);Thank you. Regards
    Tarik

    Hi,
    your snippet works. I have tried it and it does what
    you expect. There must be something wrong in the
    surrounding code. You already added that
    System.out.println. Doesn't give this more
    information?Thank you very much for the reply. I tested it with the System.out. but even though there were 3 dirfferent nodes selected the Vector always had a size of 1. I've replaced the Vector with a Hash Set and it worked that way.
    But anyway thank you it's good that this question mark is cleared, so I do not have to discriminate Vector's :-) It must have been something else that was causing that problem.
    Tarik.

  • Vector.contains (using a custom object)...

    hi!
    This is probably a simple question, but I just dont know the answer...
    I have created a vector that contains objects; those objects contain (1) String and (2) int.
    What i want to do is create a custom .contains function to search the vector for only the string, rather than the string and the number wrapped in the object.
    So.. If I were to write myVector.contains("Java") - I would want to know if the word "Java" existed in the vector
    already, while ignoring the integer value associated with it.
    Any ideas? -- code below
    Vector myVector = new Vector<myObject>();
    myObject{
    String text;
    int num;
    }

    As suggested, use a different data structure. Is the String unique? Then a Map is a perfect fit.
    [http://java.sun.com/docs/books/tutorial/collections/index.html]

  • How do check the whether the vector contain specific value

    I store the value retrive from select statement into vector .How do I check if the value is in the vector list . The value I am checking for is from combobox identified as obj.value. Curently I using the following syntax to check whether value is in vector or not.
    if (tran_typ.Contains(obj.value))
    Please answer me soon.

    should be:
    for (int x=0; x<vector.size(); x++)
          MyObject o = (MyObject) vector.elementAt(x);
          if (value == o.getMyValue())
                 //do something
    }Sorry, it is 2:30 in the morning!!!
    Thanks,
    Harold Clements

  • Can Vector contain ResultSet which is a Interface

    What i am trying is to execute 3 different SQL in a Bean and try it to transfer in a JSP.I am using Vector for this work.I am putting the ResultSet in the Vector and transfer that Vector to the Jsp,In which i am displaying the Result.
    I wanted to know that Is it possible to do the thing in this way.Or some other way is there.
    Could any one tell me the Solution.

    May be I 'm wrong, but the objets implementing the ResultSet interface
    must be serializable and have a public default constructor if you want
    to serialize/deserialize them. I don't think the most know drivers
    are offering you these features.
    Even if it's feasible, I don't think serializing a whole data set is
    really a good idea, because of the big overhead of doing this.
    You'd better convert the resultSet into smaller objects and
    only pass a set of them to your jsp only under request,
    not the whole thing once.
    Hope this helps

  • How to Perform Java Vector Difference?

    Hello All,
    I need some help for Difference Between 2 Vectors Implementation
    I have written a short program to explain what I exactly one.. BasicallY I am looking for a method that returns a Vector containing the elements of vect1 minus the elements of vect2
    I tried using 2 for loops but its not possible. Is there a built in or a easier way to achieve this difference between 2 Vectors?
    import java.util.Vector;
    public class VectorDifference {
         static Student stud1 = new Student("Test1", 15);
         static Student stud2 = new Student("Test2", 15);
         static Student stud3 = new Student("Test3", 15);
         static Student stud4 = new Student("Test1", 15);
         static Student stud5 = new Student("Test3", 15);
         static Student stud6 = new Student("Test7", 15);
         static Vector vect1 = new Vector();
         static Vector vect2 = new Vector();
         public static void main(String[] args) {
              vect1.add(stud1);
              vect1.add(stud2);
              vect1.add(stud3);
              vect1.add(stud4);
              vect1.add(stud5);
              vect1.add(stud6);
              System.out.println("Vector 1 - Vector 2");
    class Student{
         String name;
         int age;
         public int getAge() {
              return age;
         public void setAge(int age) {
              this.age = age;
         public String getName() {
              return name;
         public void setName(String name) {
              this.name = name;
         public boolean equals(Object obj){
                   if(!(obj instanceof Student)){
                        return false;
                   Student student2 = (Student)obj;
                   if(name.equals(student2.getName()) && age == student2.getAge()){
                        return true;
                   return false;
         public Student(String name, int age) {
              this.name = name;
              this.age = age;
    }

    Brynjar wrote:
    Btw, vectors went out of fashion many many years ago. Use ArrayList instead.Around '98 with the introduction of ArrayList.
    The OP could also consider using generics, and using a local variable instead of a field, esp a static field, when ever possible.
    Edited by: Peter__Lawrey on 04-Jul-2009 14:44

  • Set and get values with vector

    I have a class that that querys a db and sets a value of the result to a vector array. Is it possible to set and retrieve that vector array using the set and get methods?
    ex:
    my class:
    sql = "Select ...";
    Vector fName = new Vector();
    rs = sqlStatement.executeQuery(sql);
    if (rs != null) {
    while (rs.next()) {
    fName.add(rs.getString("fName") + "");
    rs.close();
    setFName(fName);
    how would I set up the set and get methods???
    thanks

    I am unsure of what you are asking:
    A Vector has set and get methods for it, you use indexes of the array to say what element you want to work with.
    If you are asking how do you know what elements of the Vector contain which data columns, you have to remember how you put them in.
    If you are asking if you can use set to load the Vector: then NO, you have to have elemenets already there to change, use the add method.
    If you are asking how to access the elements of the Vector you use an Enumeration:
    for(java.util.Enumeration e = v.elements(); e.hasMoreElements();){
    s = (java.lang.String) e.nextElement();
    vl.add(s.substring(0, 12));
    If you are asking something else: please elaborate what you want--my brain may not be very functional this morning.

  • HOW TO DELETE DUPLICATE ELEMENT IN A VECTOR

    Hi everybody!
    If I've a vector like this vectA={apple,orange,grape,apple,apple,banana}
    and I want final result be vectB={apple,orange,grape,banana}.
    How should I compare each element in vectA and delete duplicate element. Like here duplicated element is apple. Only one apple remain in the vectB.
    Any help,
    Thanks.

    Hello all. Good question and good answers, but I would like to elaborate.
    To begin with, you specifically asked to map the following:
    {apple,orange,grape,apple,apple,banana} ==> {apple,orange,grape,banana}
    Both of cotton.m's solutions do NOT do this, unfortunately. They are both useful in particular cases though, so think about what you're trying to do:
    cotton.m's first solution is best if order does not matter. In fact, as flounder first stated, whenever order doesn't matter, your most efficient bet is to use a Set instead of a List (or Vector) anyways.
    Set vectB = new HashSet(vectA);This code maps to {banana, orange, grape, apple}, because HashSets are "randomly" ordered.
    cotton.m's second solution is good if you want to impose NEW ordering on the List.
    Set vectB = new TreeSet(vectA);This code maps to {apple, banana, grape, orange}, because TreeSet uses alphabetical-order on Strings by default.
    java_2006, your solution is the most correct, but it's a little verbose for my taste :)
    more importantly, the runtime-efficiency is pretty bad (n-squared). calling Vector.contains performs (at worst) n comparisons; you're going to call it n times! Set.contains usually performs 2 comparisons (constant, much better), so I suggest you USE a Set to do the filtering, while still sticking with your good idea to use a List. When the ordering is "arbitrary" (so can't use TreeSet) but still relevant (so can't use HashSet), you're basically talking about a List.
    I think saving A LOT of time is worth using A LITTLE extra space, so here, let's save ourself some runtime, and some carpal-tunnel.
    import java.util.*;
    class Foo {
         public static void main(String[] args) {
              String[] fruits = {"apple","orange","grape","apple","apple","banana"};
              List     l = Arrays.asList(fruits),
                   m = filterDups(l);
              System.out.println(m);
         // remember, both of the following methods use O(n) space, but only O(n) time
         static List filterDups(List l) {
              List retVal = new ArrayList();
              Set s = new HashSet();
              for (Object o : l)
                   if (s.add(o))
                        retVal.add(o);     // Set.add returns true iff the item was NOT already present
              return retVal;
         static void killDups(List l) {
              Set s = new HashSet();
              for (Iterator i = l.iterator(); i.hasNext(); )
                   if (! s.add(i.next()))     
                        i.remove();
         // honestly, please don't use Vectors ever again... thanks!
         // if you're going to be a jerk about it, and claim you NEED a Vector result
         // then here's your code, whiner
         public static void mainx(String[] args) {
              String[] fruits = {"apple","orange","grape","apple","apple","banana"};
              List l = Arrays.asList(fruits);
              Vector v = new Vector(l);
              killDups(v);
              System.out.println(v);
    }

  • My array in the Vector is not working

    Hi all,
    I have my program sample where problem is the content of vector of (array) only produce the last items of the array, but during the for loop, my vector (m_Dist) gives the correct contents.
    my question is why is my vector produce such output?
    pls help
    tq
    import java.util.Vector;
    public class testNum{
         static double[][] dist;
         static Vector m_Dist;
         public static void main(String args[]){
              int[][] v = {{1,2,3,4,5}, {2,1,3,4,5}, {6,7,8,2,3}};
              int[][] m_Data = {{3,2,4,1,4}, {2,5,4,9,8}, {8,7,8,6,5}};
              m_Dist = new Vector<double[][]>();
              dist = new double[v.length][2];         
             for (int i=0; i<m_Data.length; i++){
                  int m_Query[] = m_Data;
              for (int j = 0; j <v.length; j++) {
              int[] example = v[j];          
                        double dis = 0.0;
              dis = EuclideanDistance(example, m_Query);
              dist[j][0] = dis;
              dist[j][1] = (double) (j + 1);
              dist = bubleSort(dist);
              m_Dist.add(dist);     
                   //test here - uncomment and will get the output it suppose to be
    //double[][] m_dist;
                   //m_dist = (double[][]) m_Dist.elementAt(i);
              //for(int j=0; j<m_dist.length; j++){
                   //System.out.println(i + " " + m_dist[j][0] + " ---> " + m_dist[j][1]);
         //System.out.println();
    //here it produce only the last items in the vector/array
              double[][] m_dist;
              for(int i=0; i<m_Dist.size(); i++){
              m_dist = (double[][]) m_Dist.elementAt(i);
              for(int j=0; j<m_dist.length; j++){
                   System.out.println(i + " " + m_dist[j][0] + " ---> " + m_dist[j][1]);
         System.out.println();
         public static double EuclideanDistance(int[] example, int[] query) {
              double dist = 0.0;
              for (int i = 0; i < example.length; i++)
              dist += (double) Math.pow(example[i] - query[i], 2.0);
              return Math.sqrt(dist);
         public static double[][] bubleSort(double[][] distances) {
              double tempDist = 0.0;
              double newOrigPos = 0.0;
              for (int i = 0; i < distances.length - 1; i++) {
              for (int j = 0; j < distances.length - 1; j++) {
                   if (distances[j][0] > distances[j + 1][0]) {
                   tempDist = distances[j][0];
                   newOrigPos = distances[j][1];
                   distances[j][0] = distances[j + 1][0];
                   distances[j][1] = distances[j + 1][1];
                   distances[j + 1][0] = tempDist;
                   distances[j + 1][1] = newOrigPos;
              return distances;

    sam.09 wrote:
    only produce the last items of the array,This makes me very suspicious. Without closely looking at your code I suspect what you are doing is simply adding the same reference to your Vector multiple times. Imagine that Fred is pointing at a piece of paper. On that piece of paper is written the word "hello". You then add Fred to your Vector. Now you change the word on the piece of paper to "dolly". Fred is still pointing to the same piece of paper although the data stored on the piece of paper has changed. You then add Fred again to the Vector. Now your Vector contains Fred twice and both of those Fred's point to the same piece of paper. You repeat this multiple times.

  • VEctor: Problem in arithmetical operation

    The problem with the following code is that when an element is accessed with v.elementAt() the compilation is OK. But if I try to do some arithmetic operation on the element, it won't compile, giving the message -
    VectorDemo.java:36: operator * cannot be applied to java.lang.Object, int
    System.out.println("Result: "+v.elementAt(3)*2);
    Is it because of <Object> type declaration of Vector? If so how to do arithmetic operation with an element of a vector which may have Double, Float or Integer type of elements in the same vector?
    import java.util.*;
    class VectorDemo
         public static void main(String args[])
              Vector<Object> v=new Vector<Object>(3,2);
              System.out.println("Initial size: "+v.size());
              System.out.println("Initial capacity: "+v.capacity());
              v.addElement(new Integer(1));
              v.addElement(new Integer(2));
              v.addElement(new Integer(3));
              v.addElement(new Integer(4));
              System.out.println("Capacity after four additions: "+v.capacity());
              v.addElement(new Double(5.45));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Double(6.08));
              v.addElement(new Integer(7));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Float(9.4));
              v.addElement(new Integer(10));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Integer(11));
              v.addElement(new Integer(12));
              System.out.println("First element : "+v.firstElement());
              System.out.println("Last element : "+v.lastElement());
              System.out.println("Find Result: "+v.elementAt(3));     //<------ if replaced with:
                                    //System.out.println("Find Result: "+v.elementAt(3)*2);
              if(v.contains(new Integer(3)))
                   System.out.println("Vector contains 3.");
              Enumeration vEnum=v.elements();
              System.out.println("\nElements in vector: ");
              while(vEnum.hasMoreElements())
                   System.out.println(vEnum.nextElement()+" ");
              System.out.println();
    }

    Here's the correct code.
    import java.util.*;
    import java.lang.Number;
    class VectorDemo
         public static void main(String args[])
              //initial size is 3, increment is 2
              String s;
              int i=0;
              Vector<Number> v=new Vector<Number>(3,2);
              System.out.println("Initial size: "+v.size());
              System.out.println("Initial capacity: "+v.capacity());
              v.addElement(new Integer(1));
              v.addElement(new Integer(2));
              v.addElement(new Integer(3));
              v.addElement(new Integer(4));
              System.out.println("Capacity after four additions: "+v.capacity());
              v.addElement(new Double(5.45));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Double(6.08));
              v.addElement(new Integer(7));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Float(9.4));
              v.addElement(new Integer(10));
              System.out.println("Current capacity : "+v.capacity());
              v.addElement(new Integer(11));
              v.addElement(new Integer(12));
              System.out.println("First element : "+v.firstElement());
              System.out.println("Last element : "+v.lastElement());
              System.out.println("Result: "+Integer.parseInt(v.elementAt(3).toString())*2);
              if(v.contains(new Integer(3)))
                   System.out.println("Vector contains 3.");
              //enumerate the elements in the vector.
              Enumeration vEnum=v.elements();
              System.out.println("\nElements in vector: ");
              while(vEnum.hasMoreElements())
                   System.out.println(vEnum.nextElement()+" ");
              System.out.println();
    }

  • Randomising order of elements in vectors

    hi
    i have a vector containing vectors containing Doubles (nightmare, i know!). Just wondering if there's an easy way of randomising the order or the elements in the main vector.
    thanks,
    al

    This can be improved.
    public class ARandouPermutation{
    public static void main(String[] args) throws Exception{
    java.util.Vector vec = new java.util.Vector();
    for(int i=0;i<64;i++){// 64 is an example
        vec.add(new Double(i*1.0));
    Object[] tmp0 = vec.toArray();
    int originalSize = vec.size();// obtaining the original size of the Vector
    vec.clear();  // setting to size zero
    Object[] tmp1 = new Object[originalSize];
    int[] indexarr = randPermute(originalSize);// this method is defined below
    for(int j=0;j<indexarr.length;j++){
        tmp1[j] = tmp0[indexarr[j]];
    tmp0=null;
    arr=null;
    for(int j=0;j<originalSize;j++){// this can be replaced by java.util.Arrays.asList(Object[])
      vec.add(tmp1[j]);
      System.out.println(((Double)vec.get(j)).toString());//test output
    public static int[] randPermute(int L){// length L of the array returned is passed as an argument
       if(L<0) throw new IllegalArgumentException();
       int[] arr = new int[L];
       java.util.Random rand = new java.util.Random();
       for(int j=0;j<L;j++) arr[j]=j;
       int tmp, index=0;
    Label:   while(index<L){
           tmp = rand.nextInt(L);
           for(int j=0;j<index;j++) {
                if(tmp==arr[j]) continue Label;
            arr[index]=tmp;
            index++;
       return arr;
    }

  • Merging two sorted Vectors into one

    I wish to write a function that will accept two Vectors which are sorted and merge them into a single sorted Vector. I plan to use the compareTo() function to perform the comparisons between objects. I want the function to do this task for Vectors containing Integer, String, or any User Defined Classs (both the vectors will be containing objects of same class though).
    However, I am unable to do this because whether I use an iterator or write a loop to acces the elements of the Vector, I am required to typecast the returned object. I am using J2SE 1.4.2
    1 Vector mergeSortedVectors(Vector a, Vector b) {
    2         Vector c = new Vector();
    3         int p1=0, p2=0;
    4         while(p1<a.size() && p2<b.size()) {
    5                int result = ((Object)a.get(p1++)).compareTo((Object)b.get(p2++));
    6                // insertion logic
    7         }
    8 }Line no 5 gives me a compile error: Object.compareTo() not found
    Please help

    Cast it to Comparable instead of Object.

  • Vector to String[] Conversion

    Hi All,
    I am trying to convert Vector to String Array. the problem is when I tried to print the String Array out side the loop I am getting only last value.
    I want to pass String Array to another function.
    How to do that?
    Find the code below:-
    Vector vec=new Vector()
    vec.add("abc\\aa.doc");
    vec.add("abc\\ccc.doc");
    vec.add("abc\\bb.doc");                  
    String [] arr=new String[vec.size()];
          for(int i=0;i<=vec.size();i++){
                       arr=vec.get(i).toString();
    System.out.println( "ARRAY" + arr);
    Current Output
    Output :- ARRAY abc\\bb.doc
    Desired Output
    ARRAY abc\\aa.doc,,abc\ccc.doc,abc\\bb.doc
    Thanks.

    OK,
    My vector contains Objects...
    I tried to use the following code
    String[] attachments = new String[setOfHandle.size()];
    for (int i = 0; i < setOfHandle.size(); i++) {
           attachments[i] = String.valueOf(setOfHandle.get(i));
         // if attachments exists, add them
         if ( attachments != null ) {
                           addAtta( maild, attachments );
                           checkPoint = false;
    }In the above code setOfHandle is a vector contains objects.. I need to convert it to String[] and pass it to addAtta.
    While doing this I am getting an error
    java.lang.ArrayIndexOutOfBoundsException: 1

Maybe you are looking for

  • Is there a way to script "expand appearance"?

    I have created a method to create line art roof shingles row-by-row. I think something like this is a good candidate for scripting, but I run into a dead-end quickly when trying to script this. Basically, I use "expand appearance" multiple times duri

  • Creative Zen Style 300 - charging

    Hi,?i have a big problem. I bought mp4 about 2 weeks ago. I listened to it from time to time. Yesterday, my mp4 warned me that the battery is very low. So i connected USB to my mp4 and to the charger and put it in to the socket. My mp4 is charging fo

  • 7.3.2.6 crashes when coming out of standby mode

    Has anyone else seen this problem with iTunes 7.3.2.6? It crashes when coming out of standby mode. There is an error report I can send to Microsoft, but since it's an Apple program, I never send it. Using standby was OK with iTunes 7.2.

  • Performance and Sprite objects

    I've written an application in Flex 2 that consists of several accordions containing custom canvas objects, and it is having performance problems. I'm running the application within IE 6.0 under Windows 2000. The application loads an XML file and use

  • Digital signature Filter / SubFilter

    Hi, i have a question regarding the use of digital signatures. As a filter value i am usingAdobe.PPKLite but i am not quite sure about the SubFilter. As i understand there are three possible values: - adbe.pkcs7.detached - adbe.pkcs7.sha1 - adbe.x509