The Vector class

The vector is it deprecated?
Because some of me friends said yes, and some no!

No. Officially it is not deprecated.
However the introduction of the Collections framework have provided superior tools to Vector.
If all you want is a dynamic array (which is essentially what it was used for) the main recommendation is to use ArrayList as it is exactly the same functionality, but has a faster implementation.
So in that sense, most places you originally wanted to use Vector, you should instead use ArrayList. Also is you look in the Collections framework documentation, it is listed as a Legacy class.
But no, Vector has not been officially deprecated.

Similar Messages

  • Where is the Vector class? Can't use it.

    Hello!
    I've downloaded Flex Builder 3 Trial from Adobe's website.
    Now I want to use the Vector class, but this code for example:
      var v:Vector.<String>;
      v = new Vector.<String>();
    Gives me this error:
    1046: Type was not found or was not a compile-time constant: Vector.
    At the IDE, going to
      Window -> Preferences -> Flex -> Installed Flex SDKs
    I can see that I have Flex 3.2 SDK.
    Even more than that: When I search for "Vector" in the help ("Adobe® Flex™ 3 Language Reference") I can see all the details about Vector.
    What can I do?
    I'd like to avoid installing any newer SDKs due to all the bugs I see listed here in the forums.
    Thank you!

    It looks like you are trying to type Java code in Flex Builder.  Flex applications are generally built using ActionScript.
    These docs might help you learn ActionScript:
    http://www.flexafterdark.com/docs/ActionScript-Language
    http://www.flexafterdark.com/docs/ActionScript-vs-Java
    I hope that helps...
    Ben Edwards

  • How can I extend the Vector class?

    Hi All,
    I'm trying to extend the Vector class so I can get add a .remove(item:T) method to the class.  I've tried this:
    public class VectorCollection extends Vector.<T>
    That gives me the compile error "1017: The definition of base class Vector was not found"
    So then I tried:
    public class VectorCollection extends Vector
    Which gives me the compile error "1016: Base class is final."
    There must be some way to extend the Vector class, though, as on the Vector's official docs page it says:
    Note: To override this method in a subclass of Vector, use ...args for the parameters, as this example shows:
         public override function splice(...args) {
           // your statements here
    So there must be a way to extend the Vector class.  What am I doing wrong?

    No. AS3 doesn't currently have full support for generic types; Vector.<T> was added in an ad-hoc ("ad-hack"?) way. We are considering adding full support in a future version of ActionScript.
    Gordon Smith
    Adobe Flex SDK Team

  • Regarding Vector classes in JSP

    Hello,
    Where we actually use the vector classes in jsp page.Is there any necessary to use Vector classes in jsp programs instead of database.Or is there any conditions like here we have use vector instead of DataBase.

    JSP pages are part of the "view" layer in the MVC design pattern.
    As such, it is advisable to seperate them from the model/control layer. For this reason, database code in a JSP page is undesirable.
    The controller normally queries the model, places the results into a collection/vector, makes them available to the jsp page. All the jsp page knows is that it gets the collection - nothing about where it came from or how the model is accessed.
    It is not NECESSARY to do so. You can easily put SQL statements, and scriptlets into your JSP pages. But keeping that stuff out makes for more easily understood and maintainable web applications.
    Cheers,
    evnafets

  • Vector class warning

    i am learning to use the vector class. i am getting this warning but the program still runs:
    warning: [unchecked] unchecked call to addElement(E) as a member of the raw type java.util.Vector
    heres the code:
    int a=0;
    Vector i=new Vector();
    i.addElement(a);//this is the line causing the warning
    System.out.println(i.elementAt(0));why is the compiler returning this warning but still allowing the program to run?

    Getting back to the original quesiton......
    After you do some research on generics, try to get rid of all those warnings by implementing generics properly in your code. Its not hard once you correct a few such problems and see how its done.
    Although you don't have to correct them since they are only warnings, its good practice since seeing 100 generics warnings may hide other types of warnings you should really look into. Note you can't always get rid of the warnings since generics aren't backwardly compatable with certain java classes (such as ArrayList.toArray()?). To hide these warnings, put @suppressWarnings("unchecked") above the function you want to hide those warnings.
    suppressWarnings will only work for jdk 1.5 and later(?).
    By the way, your code has i.addElement(a) where a is an integer. You might want to read up on autoboxing since java converts this int to an Integer.
    Edited by: njb7ty on May 31, 2008 4:36 PM

  • The get() of Vector class, is it thread safe??

    Hi all:
    the get() of Vector class, is it thread safe?? I looked into the API, but no info is available, so any help is appreciated

    You just have to look out when you perform two or more methods on the Vector in sucession. Then it's better to lock on the vector itself. If you for instance access the vector to query whether the size is greater than zero and immediately remove an item while another thread is removing elements from the same vector, you might get a dirty read and call get() on the vector while there are no elements left.

  • Vector manipulation for the Thread Class

    Hello everyone,
    Trying to create a producer consumer class
    Please help with consumer method.
    Here is my code:
    // Class
    import java.util.*;
    public class ProducerConsumer
         // A private Vector field.
          Vector vector = new Vector();     
               Object element;
         // A flag to indicate completion.
         private boolean produceFlag=false;
         // A method setDone() to indicate completion.
         public void setDone()
              produceFlag=true;
         // A method isDone()  to check completion.
          public boolean isDone()
               if (produceFlag)
                    return false;
               else
                    return true;
              // A produce() method  - The produce method checks if the vector is empty.
              // If it is, it will get a random number 'x' between 1 and 10.
              // The produce method then gets 'x' number of random numbers between 20 and 30,
              // displays the number on your screen and inserts them into the vector and notify
              // other threads that it is done. If the vector, is not empty then the produce method
              // just waits. You can use the following formula
              // to get random numbers between a range:
         public  synchronized void produce()
         try
              if (vector.isEmpty())                
                   int range =1;
                   range = (int) (Math.random() * 10);                
                   System.out.println("hello" + range);
                   for(int i=0;i<range;i++)
                        // convert int to Integer Object.
                        Integer I=new Integer((int) ( ( i - i + 1) * Math.random() + i ));                    
                        vector.addElement(I);                                                            
                   //loop thought the elements in a vector to print
                   for (int j=0; j < vector.size(); j++)
                        // set reference to each element inside the vector as Object.               
                        element=vector.elementAt(j);
                        /* cast the object variable to Integer.
                        ** call intValue() method of Integer
                        ** object that returns the int
                        ** inside an Integer Object.
                        // print the int just extracted.
                        System.out.println("Integer Found: " + ((Integer) element).intValue());
                        notifyAll();
                        setDone() ;
                   else
                        // Vector is not empty - it waits
                        wait();
                        System.out.println("i am not empty");                    
              }          // exception throws by wait().
              catch (InterruptedException e)
                   System.out.println(e.toString());
         // A consume method - The consume() method checks
         // if the vector is empty.
         // If it is, it checks if the producer is done.
         // If it is - the program exits.
         // If the producer is not done the consumer just waits. 
         // If the vector is not empty, the consume method
         // retrieves at most three items in FIFO
         // (First In First Out)
         // order from the vector, displays the numbers on your screen
         // and
         //  removes them from the vector.
         // If there are less then three items -
         // the consumer consumes all. If there are more than or
         // equal to three items, the
         // consumer consumes three items.
          public  synchronized void consume()
              try
                   if (vector.isEmpty())
                     if (isDone() )
                                    System.out.println("Done");
                                    System.exit(0);
                          else
                                    System.out.println("wait");
                                    wait();
                   else
                        // Consume retrives at most three items (1in,out)
                        // from vector, display the number on the screen
                        // removes from items from vector
                        // if less then 3 delete them all
                        for (int j=0; j < vector.size(); j++)
                             System.out.println("Integer Found: " + ((Integer) element).intValue());
                             vector.removeElementAt(j);      
              catch (InterruptedException e)
                   System.out.println(e.toString());
    // exception throws by wait().
    }THANKS A LOT FOR YOUR HELP:)

    How do I implement the logic to retrieves at most
    three items in (First In First Out) and removes them
    from the vector.
    If there are less then three items - the consumer
    consumes all. If there are more than or equal to
    three items, the consumer consumes three items.You start by looking at the javadocs for Vector to determine which methods on it might help you....
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html

  • Execute jar file: "could not find the main class" program will terminate

    Hey,
    I am new to Java. I have started to make a small java program which supposed to help me at my studies to lean the Dominic Memory System. I have used the latest version of Netbeans 5.5.1 to build my program in. I have two problems which I cannot figure out how to solve, please help me.
    The first problem is that the java script I have made works when I compile it in Netbeans, but when I create a Jar file it does not work. I receive a pop up message in windows ?could not find the main class program will terminate? when I execute the jar file.
    The second problem I have is that I need to compare the strings generated by the "numbers" and "TIP" and if the numbers is not identical the numbers in the ?Center? JPanel should be highlighted as red.
    If anyone would like to clean up the code I would be pleased. I have copied quite a lot from anyone because of my one lack of knowledge.
    * GoListener.java
    * Created on 12. september 2007, 21:48
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package grandmaster;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Vector;
    import java.util.StringTokenizer;
    import java.awt.Color;
    * @author Computer
    public class GoListener implements ActionListener {
    private JTextField viewer;
    private JTextField TIP;
    private JTextField freq;
    private JTextField max_num;
    private Vector numbers;
    public GoListener(JTextField j,JTextField k, JTextField m, JTextField f, Vector n) {
    freq = f;
    max_num = m;
    viewer = j;
    numbers = n;
    TIP = k;
    public void actionPerformed(ActionEvent e){
    int time = Integer.valueOf(max_num.getText());
    int f = Integer.valueOf(freq.getText());
    if (e.getActionCommand() == "GO") {
    for (int i = 0; i< time;++i) {
    int number=0;
    number = (int)Math.floor(100*Math.random());
    while(number>51){
    number = (int)Math.floor(100*Math.random());
    if(number<=9){
    viewer.setText(" "+"0" + String.valueOf(number) + " ");
    } else{
    viewer.setText(" " + String.valueOf(number) + " ");
    viewer.paintImmediately(viewer.getBounds());
    numbers.add(number);
    try {
    Thread.sleep(f*1000);
    } catch (Exception exp) {
    viewer.setText(" XX ");
    viewer.paintImmediately(viewer.getBounds());
    if (e.getActionCommand() == "VIEW") {
    try {
    //int numb = Integer.valueOf( TIP.getText() ).intValue();
    StringTokenizer tokenizer = new StringTokenizer(TIP.getText(), " ");
    String[] split = null;
    int tokenCount = tokenizer.countTokens();
    if (tokenCount > 0) {
    split = new String[tokenCount];
    for (int current = 0; current < tokenCount; current++) {
    split[current] = tokenizer.nextToken();
    viewer.setText(" " + String.valueOf(numbers) + " ");
    // k=numbers(1);
    /*while(c<i){
    String.valueOf(k).equals(split[1]);
    c++;
    TIP.setText(" " + split[2] + " ");
    } catch (Exception exp) {
    try {
    //string testit = numb.toString();
    //String str = "" + numb;
    //viewer.setText(str);
    //viewer.setText(numbers.toString());
    numbers.clear();
    } catch (Exception exp) {
    * Main.java
    * Created on 12. september 2007, 21:07
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package grandmaster;
    import java.util.Vector;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.JButton;
    import java.awt.*;
    import grandmaster.GoListener;
    * @author Computer
    public class Main extends JFrame {
    private JTextField viewer;
    public JTextField TIP;
    // private TextInputPanel TIP;
    private Vector numbers;
    /** Creates a new instance of Main */
    public Main() {
    numbers = new Vector();
    JPanel p = new JPanel(new GridLayout(0,4));
    JButton go = new JButton();
    JButton view_num = new JButton();
    go.setText("Go!");
    go.setVisible(true);
    go.setActionCommand("GO");
    view_num.setText("VIEW");
    view_num.setVisible(true);
    view_num.setActionCommand("VIEW");
    JTextField max_num = new JTextField();
    max_num.setText("5");
    JTextField freq = new JTextField();
    freq.setText("1");
    viewer = new JTextField();
    viewer.setText("XX");
    TIP = new JTextField("");
    p.add(go);
    p.add(max_num);
    p.add(freq);
    p.add(view_num);
    getContentPane().add(p,BorderLayout.NORTH);
    getContentPane().add(viewer,BorderLayout.CENTER);
    getContentPane().add(TIP,BorderLayout.SOUTH);
    setSize(200,200);
    GoListener g = new GoListener(viewer,TIP,max_num, freq, numbers);
    go.addActionListener(g);
    view_num.addActionListener(g);
    * @param args the command line arguments
    public static void main(String[] args) {
    // TODO code application logic here
    Main window = new Main();
    window.setVisible(true);
    }

    NetBeans questions should be posted to the NB site. It has mailing lists and associated forums.
    This tutorial from the NB site addresses running programs outside of NB
    http://www.netbeans.org/kb/articles/javase-deploy.html
    When you compare objects, use ".equals()" and reserve == for comparing values.

  • 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.

  • How to associate lines in a text file as an elements of the Vector?

    Hi!
    I have used BufferedReader(new FileReader(c:/java/MyText.txt)) to read from MyText.txt file. Now I know how to load content of this file (every line in file describes each photo in my photo-set) into a Vector. But how to associate lines of MyText.txt as an elements of the Vector?
    Thanks Felipe for his help.
    DM.

    Thank you telism,
    Let me tell you the whole story.
    I'm trying to write an application which has to show my image files (set of photos) with a text description. The list of image files placed into the JList. So, when I select a file from the JList it shows me an image (everything is OK).
    But, every image has it's text description in MyText.text file. It's a file with each text line for every image. Actually, I am trying to connect two actions - showing my image and setting it's specified text line description (from MyText.txt) in a JTextArea. I thought that the best way to do this with my text it is like I did it with my images through Vector. But No Success.
    Can You help me on that? If You will show me how to do it on my example I will really appreciate it.
    Thank You DM.
    Here is my application:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class UnitA extends JPanel implements ListSelectionListener {
    BasicUnitA Myapplet;
    JPanel listPanel, picturePanel;
    Vector imageNames1;
    JList list1;
    JLabel picture1;
    JScrollPane listScrollPane1, pictureScrollPane1, TSP1;
    JTextArea TA1;
    int index;
    UnitA (BasicUnitA parent, boolean p1, boolean p2) {
    Myapplet=parent;
    //Read image names from a properties file
    ResourceBundle imageResource1;
    try{
    imageResource1 = ResourceBundle.getBundle("imagenames1");
    String imageNamesString1 = imageResource1.getString("images");
    imageNames1 = parseList(imageNamesString1);
    } catch (MissingResourceException e) {
    System.err.println("Please, add properties file with image names.");
    System.exit(1);
    //Create one list of images and put it in a scroll pane and panel
    list1 = new JList(imageNames1);
    list1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list1.setSelectedIndex(0);
    list1.addListSelectionListener(this);
    listScrollPane1 = new JScrollPane(list1);
    listScrollPane1.setPreferredSize(new Dimension (120,120));
    //Set up the picture label and put it in a scroll pane
    ImageIcon firstImage1 = new ImageIcon("java/Applications/images/fotos/" +
    (String)imageNames1.firstElement());
    picture1 = new JLabel(firstImage1);
    picture1.setPreferredSize(new Dimension (firstImage1.getIconWidth(),
    firstImage1.getIconHeight()));
    pictureScrollPane1 = new JScrollPane(picture1);
    pictureScrollPane1.setPreferredSize(new Dimension (500,360));
    pictureScrollPane1.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createCompoundBorder(
    BorderFactory.createLoweredBevelBorder(),
    BorderFactory.createEmptyBorder(5,5,5,5)),
    BorderFactory.createLineBorder(Color.black)));
    pictureScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLL
    BAR_ALWAYS);
    TA1 = new JTextArea();
    TA1.setLineWrap(true);
    TA1.setWrapStyleWord(true);
    TA1.setEditable(false);
    TA1.setFont(new Font("Serif", Font.PLAIN, 16));
    TSP1 = new JScrollPane(TA1);
    TSP1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_
    ALWAYS);
    TSP1.setPreferredSize(new Dimension(500,40));
    TSP1.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createCompoundBorder(
    BorderFactory.createLoweredBevelBorder(),
    BorderFactory.createEmptyBorder(5,5,5,5)),
    BorderFactory.createLineBorder(Color.black)));
    public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;
    JList theList1 = (JList)e.getSource();
    if (theList1.isSelectionEmpty()) {
    picture1.setIcon(null);
    TA1.setText(null);
    } else {
    index = theList1.getSelectedIndex();
    ImageIcon newImage1 = new
    ImageIcon("java/Applications/images/fotos/" +
    (String)imageNames1.elementAt(index));
    picture1.setIcon(newImage1);
    picture1.setPreferredSize(new Dimension (newImage1.getIconWidth(),
    newImage1.getIconHeight()));
    picture1.revalidate();
    try{
    BufferedReader reader = new
    BufferedReader(new FileReader("c:/java/Applications/MyText.txt")));
    String str;
    while((str = reader.readLine()) != null) {
    TA1.setText(TA1.getText()+str);
    reader.close();
    }catch(IOException evt){};
    protected static Vector parseList(String theStringList) {
    Vector v = new Vector(10);
    StringTokenizer tokenizer = new StringTokenizer (theStringList, " ");
    while (tokenizer.hasMoreTokens()) {
    String image = tokenizer.nextToken();
    v.addElement(image);
    return v;

  • How to understand the Vector source code for function elements()?

    hello all:
    This following code snippet is extracted from java.util.Vector source code.
    who can tell me how i can understand what the function nextElement does?
    thank you
    public Enumeration elements() {
         return new Enumeration() {
             int count = 0;
             public boolean hasMoreElements() {
              return count < this.num_elem;
             public Object nextElement() {
              synchronized (Vector.this) {   //???
                  if (count < elementCount) {//???
                   return elementData[count++];
              throw new NoSuchElementException("Vector Enumeration");
        }

    Perhaps code would help more. This codeimport java.util.Vector;
    import java.util.Enumeration;
    import java.util.Iterator;
    public class Test {
        public static void main(String[] arghs) {
         Vector v = new Vector();
         Integer two = new Integer(2);
         // Fill the Vector
         v.add("One");
         v.add(two);
         v.add(new StringBuffer("Three"));
         // Enumerate through the objects in the vector
         System.out.println("---- Enumeration ----");
         Enumeration e = v.elements();
         while (e.hasMoreElements()) System.out.println(e.nextElement());
         // Loop through the objects in the vector
         System.out.println("---- Loop ----");
         for (int i=0; i<v.size(); i++) System.out.println(v.get(i));
         // Iterate through the objects in the vector
         System.out.println("---- Iterator ----");
         Iterator i = v.iterator();
         while (i.hasNext()) System.out.println(i.next());
    }produces this output
    ---- Enumeration ----
    One
    2
    Three
    ---- Loop ----
    One
    2
    Three
    ---- Iterator ----
    One
    2
    Three
    So, for a Vector, all three do the same thing. However, Iterator is part of the Collection Framework (see [url http://java.sun.com/j2se/1.4.2/docs/guide/collections/index.html]here). This allows you to treat a whole bunch of [url http://java.sun.com/j2se/1.4.2/docs/guide/collections/reference.html]objects which implement the Collection interface all the same way. I know this is way more than you were asking, but I hope it at least clears up what you were asking.

  • I created a vector and added objects, but the vector is empty

    I created an object called a facility, it accepts 2 strings in the creator but stores the data as a string and a float. as you can see from the code below, i have tried to create a vector object to contain facilitys and named it entries. when i add objects to this vector, the vectors size does not change, and i cannot access elements of it via their index. but when i print the vector out i can see the elements? what is going on here. i am very confused. ps, if it helps i havent worked with vectors much before.
    FacilitysTest.java
    import java.util.*;
    public class FacilitysTest {
         public static void main (String [] args) {
         Facilitys entries = new Facilitys();
         entries.add("Stage","3.56");
         entries.add("kitchen","5.00");
         entries.add("heating","2");
    //     System.out.println(entries.firstElement() );
         System.out.println("printing out entries");
         System.out.println(entries);
         System.out.println();
         System.out.println("There are "+entries.size()+" entries");
         System.out.println();
         System.out.println("modifying entry 2");
         entries.setElementAt(new Facility("lighting","1.34"), 2);
         System.out.println(entries);
         System.out.println();
         System.out.println("deleting entry 1");
         entries.remove(1);
         System.out.println(entries);
    }the following is what happens when i run this code.
    the number (0,1,2) is taken from a unique number assigned to the facility and is not anything to do with the facilitys position in the vector.
    printing out entries
    Facility number: 0, Name: Stage , Cost/Hour: 3.56
    Facility number: 1, Name: kitchen , Cost/Hour: 5.0
    Facility number: 2, Name: heating , Cost/Hour: 2.0
    There are 0 entries
    modifying entry 2
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 >= 0
    at java.util.Vector.setElementAt(Vector.java:489)
    at FacilitysTest.main(FacilitysTest.java:17)
    Press any key to continue . . .
    Facilitys.java
    import java.util.*;
    public class Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
        public void add( String name, String price ) {
             entries.add((new Facility( name, price) ));
        public Facility get(int index) {
              return ((Facility)entries.get(index));
         public float total() {
              float total = 0;
              for (int i = 0; i<entries.size();i++) {
                   total = total + ( (Facility)entries.get(i) ).getPricePerHour();
              return total;
        public String toString( ) {
            StringBuffer temp = new StringBuffer();
            for (int i = 0; i < entries.size(); ++i) {
                temp.append( entries.get(i).toString() + "\n" );
            return temp.toString();
    }

    are you reffering to where i have public class
    Facilitys extends Vector {
         private Vector entries;
         public Facilitys( ) {
                 entries = new Vector();
    That's correct. That's your problem.
    i added the extends Vector, because without it i got
    the following errors
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:14: cannot find symbol
    symbol : method size()
    location: class Facilitys
    System.out.println("There are "+entries.size()+"
    " entries");That's because you haven't implemented a size method in your class.
    ^
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:17: cannot find symbol
    symbol : method setElementAt(Facility,int)
    location: class Facilitys
    entries.setElementAt(new
    w Facility("lighting","1.34"), 2);That's because you haven't implemented setElementAt in your class.
    C:\Documents and Settings\george\My
    Documents\University\JavaCode\CM0112\FacilitysTest.jav
    a:21: cannot find symbol
    symbol : method remove(int)
    location: class Facilitys
         entries.remove(1);
    ^That's because you haven't implemented remove in your class.
    /Kaj

  • How to implement the String class "split()" method (JDK1.4) in JDK 1.3

    is it possible , with some code, to implement the split() method of the String class......which is added in JDK1.4 ..... in JDK1.3
    would be helpful if anyone could suggest some code for this...

    Here it is
    public static String[] split(String source, char separ){
    answer=new Vector();
    int position=-1, newPosition;
    while ((newPosition=source.indexOf(separ,position+1))>=0){
    answer.add(source.subString(position+1,newPosition));
    position=newPosition;
    } //while
    answer.add(source.subString(position+1,source.length-1);
    return (String[])(answer.toArray());
    } //split

  • Need help about Vector class in java

    Hello,
    I have some questions about Vector class. Please see this short code:
    Vector v = new Vector();
    v.add(New Integer(5));
    Is this the only way to add int value into vector? Performance wise, is this slow? And are there any better and faster way to add/get int element fro vector?
    Thank you very much in advance.

    Normally (up to Java version 1.4), that's the only way you can add an int to a Vector. The thing is that Vector can only contain Objects, and an int is a primitive, not an object. So you have to wrap the int in an Integer object.
    However, Java 5 has a new feature, called autoboxing, which means that the compiler automatically wraps primitive values into objects, so that you can program it like this:
    Vector v = new Vector();
    v.add(5);Note, this will not make your program faster or more efficient, because the compiler translates this automatically to:
    Vector v = new Vector();
    v.add(new Integer(5));So in the end, the same bytecode will be produced. Autoboxing is just a feature to make life more convenient for the programmer.

  • To retrieve the vector objects randomly

    Hai all,
    How can i retreive the vector objects randomly,not in the order.Thanks in advance.

    In 1.6 the Collections class has cool stuff! like sort... and Vector was enhaced to support List.... There's even an example in the tutorial. I do Luv java sometimes :-)
    There where good examples in the old 1.4/5 tutorials, which is not available from Sun any longer, but there are still a mirrors hanging around... google hard.
    Keith.

Maybe you are looking for

  • Cannot join time capsule airport network from iPad 2 or iPhone 4

    I have recently setup a new time capsule airport base station network with my new iMac (27-inch, late 2012) running OSX 10.8.2. Wi-Fe network works fine for internet access and printing from the iMac but I cannot join the wi-fi network from our iPad

  • Add Suppporting Details for more than one periods at the same time for the same Account in Planning.

    As we know, in planning form, we can add supporting details to one cell for the level 0 members intersections. But can we do that as below: add supporting details for more than one cells at the same time? I tried to do that in workspace and smartview

  • OpenMP linking problems w/ Forte 7 on Sol 8

    Hi, I am putting loop-level parallelization into an existing app and have run into a problem while linking. The API docs imply that the -xopenmp compiler flag is sufficient, but I get the following undefined symbols: __mt_MasterFunction_ __unlock_ om

  • I cannot import music into itunes

    I use the request "add folder to itunes" but the files do not appear in my library. Neither does the request "add files to itunes". I am using windows and have the newest available version of Itunes. What can I do to successfully import multiple fold

  • Latch: row cache objects

    Hello everyone, Note: Apologize for the bad formatting, tried but it seems I forgot how to use it BANNER Oracle Database 11g Release 11.2.0.2.0 - 64bit Production I've seen  high "*latch: row cache objects*" in SP/ASH report for ~14 hours back, when