Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Java Coding

Tue Nov 30, 2010 8:03 pm

HI...
i need some hints on Vector and Scalar Quantization coding ASAP :)



Vector class

Thu Dec 02, 2010 5:56 pm

Vector class is in java.util package of java. Vector is dynamic array which can grow automatically according to the required need. Vector does not require any fix dimension like String array and int array. Vector contains many useful methods. To add element in Vector, we can use add() method of vector class. To add elements at fix position, we have to use add(index, object) method.

To get value from Vector, Vector provides get() method and Vector size() method. Size() method returns total number of elements in Vector.

Vector is synchronized, ArrayList is not...

Code:
import java.util.Vector;

public class VectorExample {

    public static void main(String[] args) {

        Vector<String> vc=new Vector<String>();

        //    <E> Element type of Vector e.g. String, Integer, Object ...

        // add vector elements
        vc.add("Vector Object 1");
        vc.add("Vector Object 2");
        vc.add("Vector Object 3");
        vc.add("Vector Object 4");
        vc.add("Vector Object 5");

        // add vector element at index
        vc.add(3, "Element at fix position");

        // vc.size() inform number of elements in Vector
        System.out.println("Vector Size :"+vc.size());

        // get elements of Vector
        for(int i=0;i<vc.size();i++)
        {
            System.out.println("Vector Element "+i+" :"+vc.get(i));
        }
    }
}


Post a reply
  Related Posts  to : Java Coding
 search for coding java/jsp for translation text     -  
 data leakage detection coding in java     -  
 HI! NEW 2 Java & coding a MMOMUD -> Journey Quest Dimensions     -  
 servlet coding     -  
 I am new in PHP, want coding or PHP file     -  
 Coding serialization concepts in C++     -  
 Standard Huffman Coding     -  
 source code of huffman coding ?     -  
 Huffman coding for image compression     -  
 Arithmatic Coding Com-Decompression algorithm     -