Results 1 to 6 of 6

Thread: Retrieving information from a Vector

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Retrieving information from a Vector

    Hello,
    A vector which contains objects of type file, this is what I am trying to do but I can find a way out of it. These objects have an attribute, fileName, I want to recover. I'm not sure how much walking the vectors so if you know, I am customer information. Basically I am trying to retrieve information from the Vector. Thank you.

  2. #2
    Join Date
    Nov 2009
    Posts
    359

    Re: Retrieving information from a Vector

    Hello,
    I have not done this before, but I have tried something for you. Here is the code, see if this is what you are looking for.
    Code:
    List <File> tl = ...
    for(File f: tl) {
        String name = f.getName();
        //...
    }
    Uses of ArrayList in addition rather than concrete type Vector (and kind enough apparent List). Hope this will work for you.

  3. #3
    Join Date
    Nov 2009
    Posts
    333

    Re: Retrieving information from a Vector

    Hello,
    I have a small program with me, the code works for me, but I am not sure that this is what you want. Have a look at it
    Code:
    Public static void hand(String[] args) {
    		
    		Vector v = new Vector();
    		Long l1 = new Long("10");
    		Long l2 = new Long("20");
    v.add(l1);
    v.add(OBJ2);
    		for(int i =0; i <v.size(); i + +){
    			/ ** Retrieve one record
    then make a cast
    depending on the type of object stored here a Long
    ** / 
    			Long obj = (Long)v.get(i);
    System.out.System.out.println(obj.floatValue());
    		}
    				
    	}

  4. #4
    Join Date
    Nov 2009
    Posts
    330

    Re: Retrieving information from a Vector

    Hello,
    It would be better to use an object EnumerationI suppose the manufacturer of your object as a parameter file take the name of the file so here is an example of use.
    Code:
    Vector v = new Vector();
    / / Load the vector
    v.add(new file("test1.ext1"));
    //...
    v.add(new file("testn.extn"));
    / / Retrieving the vector
    Enumeration en = v.elements();
    / / Route your vehicle
    file = f null;
    while (en.hasMoreElements()){
       f = (file)en.nextElement();
       / / use your subject line
    }
    I hope this will help you in your code and your program.

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: Retrieving information from a Vector

    Hello,
    To summarize:
    1. Viewing iterator
    2. Not use Vector, but List
    3. Look at the javadoc
    4. An example with a Vector in java <5.0
    5. Use enumerations
    6. Re-use it Vector
    Admit that it is still huge
    In short, to condense all this, I propose:
    1. If you can, use ArrayList instead of Vector as Vector is slower because synchronized. If you can not do otherwise, is not serious is not the end of the world!
    2. If you keep the Vector, look in the Javadoc to find the method that you seek.

  6. #6
    Join Date
    Dec 2009
    Posts
    178

    Re: Retrieving information from a Vector

    Hello,
    I am new to java, but I have some code for you. I think this is the basic of teh vector that is how to declare a vector.
    Code:
    Vector v = new Vector (  ) ; 
     v.add ( "obj" ) ;
    Or you can use the following too
    Code:
    Vector v = new Vector (  ) ; 
     v.add ( 1,"obj1" ) ; 
     v.add ( 2,"obj2" ) ; 
     v.add ( 3,"obj3" ) ;

Similar Threads

  1. Replies: 4
    Last Post: 13-08-2013, 10:31 AM
  2. Error:"Problem retrieving printer information" in Access 2003
    By Jacques25 in forum Windows Software
    Replies: 5
    Last Post: 18-03-2010, 01:57 AM
  3. Retrieving files on ipod
    By Astalavista in forum Portable Devices
    Replies: 2
    Last Post: 14-05-2009, 07:32 PM
  4. Need help in retrieving CuteNews Password
    By Vandam in forum Networking & Security
    Replies: 2
    Last Post: 09-05-2009, 07:04 PM
  5. Retrieving data from damaged HDD
    By Adit in forum Hardware Peripherals
    Replies: 2
    Last Post: 22-11-2008, 05:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,513,770.98461 seconds with 16 queries