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.

Similar Messages

  • Need Help in Inner Classes

    Hi
    I joined as a faculty last week in an institution. To take class I need some information about inner classes in java.
    Basically i need where we use this concept in real time application. Now it is used by the developer or not? Moreover how it is working in java?
    Please somebody help me out...
    thanks in advance
    Chithrakumar

    I once wrote the following example class showing a bit of inner classes"public class Star {
         private String name;
         public Star(String name) { this.name= name; }
         public class Planet {
              private String name;
              public Planet(String name) { this.name= name; }
              public class Moon {
                   private String name;
                   public Moon(String name) { this.name= name; }
                   public String toString() { return name+" (orbiting "+Planet.this+")"; }
              public String toString() { return name+" (orbiting "+Star.this+")"; }
         public String toString() { return name; }
         public static void main(String[] args) {
              System.out.println(new Star("sun").new Planet("earth").new Moon("moon"));
    }Study it, run it and see if you understand what this is all about.
    kind regards,
    Jos

  • Need help about ref cursor using like table

    Hi Guys...
    I am devloping package function And i need help about cursor
    One of my function return sys_refcursor. And the return cursor need to be
    join another table in database . I don't have to fetch all rows in cursor
    All i need to join ref cursor and another table in sql clause
    like below
    select a.aa , b.cc form ( ref_cursor ) A, table B
    where A.dd = B.dd
    I appeciate it in advance

    My understanding is that you have a function that returns a refcursor and is called by a java app.
    Because this is a commonly used bit of code, you also want to reuse this cursor in other bits of sql and so you want to include it like table in a bit of sql and join that refcursor to other tables.
    It's not as easy as you might hope but you can probably achieve this with pipelined functions.
    Is it a direction that code should be going down? yes, eventually. I like the idea of pulling commonly used bits of code into a SQL statement especially into the WITH section, provided it could be used efficiently by the CBO.
    Is it worth the effort given what you have to do currently to implement it? possibly not.
    what else could you do? construct the sql statement independently of the thing that used it and reuse that sql statement rather than the refcursor it returns?
    Message was edited by:
    dombrooks

  • Need help in Creating classes for my assignment

    Hi ,
    I just started learning Java and have the following requirement
    1)     Create the following classes/interfaces using descriptions:
    a)     Account � data members : id:String, type:String, balance:BigDecimal, methods : Account, Account with String parameter, getId, getType, getBalance, setId, setType, setBalance, deposit, withdraw, compareTo, toString
    b)     Bank � data members: instance:Bank, accountsMap:Map, customersMap:Map, customersAccount:Map, transactionMap:Map, methods: getAccountsMap, getCustormersMap, getCustomersAccounts, getTransactionMap, associate, addTransaction, getAccount, getCustomer, getAccounts, getTransactions, deposit, withdraw, transfer
    c)     AccountDoesNotExistException, BankException, CustomerDoesNotExistException, InsufficientFundsException, InvalidAmountException, ZeroAmountException
    2)     Create the util package using the following class
    a)     AmountConverter � methods: fromDecimal(BigDecim     al), fromString(String)
    In 1 b how to Create Instance:bank in the class .Also how to do part2.If possible can you help me with all the parts.Based on these I've some more to do.

    Here is what I've come with
    ACCOUNT.JAVA
    import java.math.*;
    public class Account {
    private String Id;
    private String Type;
    private BigDecimal balance;
    public Account( ) {
    public Account(String Id,String Type,BigInteger balance) {
    this.Id = Id;
    this.Type = Type;
    this.balance = balance;
    public String getId( ) {
    return Id;
    public void setId(String Id) {
    this.Id = Id;
    public String getType( ) {
    return Type;
    public void setType(String Title) {
    this.Title = Type;
    public String getBalance( ) {
    return id;
    public void setBalance(String balance) {
    this.balance = balance;
    public String withdraw( ) {
    public String deposit( ) {
    public void setLastName(String LastName) {
    this.id = id;
    CUSTOMER.JAVA
    public class Customer {
    private String Id;
    private String Title;
    private String firstName;
    private String lastName;
    /** Construct a Customer with no data -- must be a no-argument */
    public Customer( ) {
    /** Construct a Customer with String Parameter */
    public Customer(String Id,String Title,String firstName,String lastName) {
    this.Id = Id;
    this.Title = Title;
    this.firstName = firstName;
    this.lastName = lastName;
    /** Return the Id. */
    public String getId( ) {
    return Id;
    /** Set the Id */
    public void setId(String Id) {
    this.Id = Id;
    /** Return the Title */
    public String getTitle( ) {
    return Title;
    /** Set the Title */
    public void setTitle(String Title) {
    this.Title = Title;
    /** Return the Firstname. */
    public String getFirstName( ) {
    return id;
    /** Set the Firstname. */
    public void setFirstName(String FirstName) {
    this.id = id;
    /** Return the Lastname. */
    public String getLastName( ) {
    return LastName;
    /** Set the Lastname. */
    public void setLastName(String LastName) {
    this.id = id;
    TRANSRECORD.JAVA
    import java.util.*;
    import java.math.*;
    public class TransRecord implements Comparable{
    private Date timeStamp;
    private String transType;
    private BigDecimal transAmt;
    /** Construct a Trans Record with no data -- must be a no-argument */
    public TransRecord( ) {
    /** Construct a Customer with String Parameter */
    public Customer(String transType,String transAmt) {
    this.transType = transType;
    this.transAmt = transAmt;
    /** Return the timeStamp. */
    public String gettimeStamp( ) {
    return timeStamp;
    /** Set the timeStamp */
    public void settimeStamp(Date timeStamp) {
    this.timeStamp = timeStamp;
    /** Return the TransType */
    public String getTransType( ) {
    return TransType;
    /** Set the TransType */
    public void setTransType(String TransType) {
    this.TransType = TransType;
    /** Return the TransAmt */
    public String getTransAmt( ) {
    return TransAmt;
    /** Set the TransAmt */
    public void setTransAmt(String TransAmt) {
    this.TransAmt = TransAmt;
    /** Return a String representation. */
    public String toString( ) {
    /** CompareTo method */
    public int compareTo(Object argument)
    ===============
    ACCOUNTDOESNOTEXISTEXCEPTION.JAVA
    public class AccountDoesNotExistException
                   extends Exception
         public AccountDoesNotExistException()
              super();
         public AccountDoesNotExistException(String message)
              super(message);
    =================
    BANKEXCEPTION.JAVA
    public class BankException
                   extends Exception
         public BankException()
              super();
         public BankException(String message)
              super(message);
    CUSTOMERDOESNOTEXISTEXCEPTION.JAVA
    public class CustomerDoesNotExistException
                   extends Exception
         public CustomerDoesNotExistException()
              super();
         public CustomerDoesNotExistException(String message)
              super(message);
    ACCOUNTDOESNOTEXISTEXCEPTION.JAVA
    public class AccountDoesNotExistException
                   extends Exception
         public AccountDoesNotExistException()
              super();
         public AccountDoesNotExistException(String message)
              super(message);
    INSUFFICIENTFUNDSEXCEPTION.JAVA
    public class InsufficientFundsException
                   extends Exception
         public InsufficientFundsException()
              super();
         public InsufficientFundsException(String message)
              super(message);
    INVALIDAMOUNTEXCEPTION.JAVA
    public class InvalidAmountException
                   extends Exception
         public InvalidAmountException()
              super();
         public InvalidAmountException(String message)
              super(message);
    ZEROAMOUNTEXCEPTION.JAVA
    public class ZeroAmountException
                   extends Exception
         public ZeroAmountException()
              super();
         public ZeroAmountException(String message)
              super(message);
    I need help with Bank Class and the util class.Correct me If I've missed any exceptions or if any syntax is wrong
    THanks
    AKsh

  • Need help about Hidden Markov Model model

    I want to make classification for EEG signal using Hidden Markov Model
    algorithm based on neural network.
    plz need help about how to implement this algorithm using LABVIEW.
    if not I want another thing to make classification.
    any one know information about this topic, send me a reply
    thanks

    Have you derrived the HMM that you want to implement?
    If so, post the algorithm and we can provide comments on how to implement it using LabVIEW.
    Message Edited by Ray.R on 04-12-2010 12:54 PM

  • Need help about boot SUNFIRE V120

    Hi all....
    I need help about how to change boot from boot net to boot disk....
    after i installed sun solaris 10 at my sunfire v120, then reboot the machine ... this sunfire still boot from net not from disk...
    can i change it?
    please i really need help ....
    thanks

    If its booted, try "eeprom boot-device=disk"
    If your at the OBP, "setenv boot-device disk".
    If that doesnt work check the value of "diag-switch?".
    It could be booting off the the diag-device instead

  • Need Help about 3D and revolving in illustrator

    I really need help about 3D, Please tell me that How i create 3D in illustrator
    i want to revolve text or shape around any object like this, any plugin? or other software required for this?
    if somebody know this it will be really help full
       http://rcgrafix.fizwig.com/1452732-large.jpg    
       http://rcgrafix.fizwig.com/1384370-large.jpg
       http://rcgrafix.fizwig.com/1062180-large.jpg
    Thanks
    Arsi

    if links are not working try Copy and paste it in to your browser address bar
    thank you

  • Need help about the SHA Message Digest ? & what is use of Message Diagest ?

    need help about the SHA Message Digest ? & what is use of Message Diagest ?
    1>i have one program of making message digest
    2>which requires two files name
    3>one for input like txt
    4> second is out put file of message digest
    can any one tell what is the use of second generated file .

    MessageDigest md = MessageDigest.getInstance("SHA");
    FileInputStream fis = new FileInputStream(args[0]);
    byte[] b = new byte[1024];
    int readed = -1;
    while((readed = fis.read(b)) > 0)
         md.update(b, 0, readed);
    fis.close();
    FileOutputStream fos = new FileOutputStream(args[1]);
    byte[] d = md.digest();
    StringBuffer sb = new StringBuffer();
    for(int i = 0; i < d.length; i++) {
         String str = Integer.toHexString(d[i] & 0xff);
         sb.append(str.length() < 2 ? "0" + str : str);
    fos.write(sb.toString().getBytes());
    fos.close();

  • Need help about 1015

    need help about 1015 it says connect iphone to itunes on screen i did it but it doesnt work and says unexpected 1015

    Try restoring it: Make sure you are following the instructions in this procedure to the letter.  Here they are, with emphasis on some easily overlooked requirements:
    Disconnect the USB cable from the iPhone, but leave the other end of the cable connected to your computer's USB port.
    Turn off the device: Press and hold the Sleep/Wake button for a few seconds until the red slider appears, then slide the slider. Wait for the device to turn off.If you cannot turn off the device using the slider, press and hold the Sleep/Wake and Home buttons at the same time. When the device turns off, release only the Sleep/Wake button.
    Continue pressing and holding the Home button while you reconnect the USB cable to the device. The device should turn on.
    Note: If you see the "low battery" screen, let the device charge for at least ten minutes to ensure that the battery has some charge, and then start with step 2 again.
    Continue holding the Home button until you see the "Connect to iTunes" screen. When this screen appears (iTunes icon and USB connector) release the Home button.
    If necessary, open iTunes. You should see the "recovery mode" alert ("iTunes has detected a phone in recovery mode").
    Use iTunes to restore the device.
    If you do not see the "Connect to iTunes" screen, try these steps again.
    If you see the "Connect to iTunes" screen but the device does not appear in iTunes, see this article and its related links.
    If you have backed up the iPhone in the past, select the device in iTunes and choose "restore from backup".

  • Hi, Need help about ios7 upgrade, after this upgrade I cannot watch youtube or any video with my Ipad,

    Hi, Need help about ios7 upgrade, after this upgrade I cannot watch youtube or any video with Ipad, and Iphone as well
    I think my wireless rooter's setting has some problem but cannot found anything to solve,
    I can watch if there is another wireless network , I tried this option in another place who has wireless network and I can watch.
    Do you have any idea to do these setting , I dont have any problem when Ipad has 6.1.3 IOS,
    need help
    thanks

    Thanks
    I will and share the result.

  • Need help about class package

    Hi All,
    I need one help.
    I have one java class under package com.abc and other java class under default package.
    How do I access java class under default package from java class under com.abc package?.
    Waiting for reply.
    Thanks

    Just add default package in your CLASSPATH seting.
    But it is recommened that all classes must belong to any package. You should avoid to use default package.

  • Need help making this class Runnable.

    Hello,
    This class (see below) is working fine the way it is but I have a little problem, I need to execute aprox 500+ commands and each command takes between 30sec to 3 minutes to complete which translate into hours for the job to finish.
    I want to speed the process by multi-tasking and executing (possibly) all commands simultaniously by somehow making this class Threaded/Runnable (miltitasking). There must be something tricky about Runtime class and cannot figured it out.
    Your help would be highly appreciated.
    Regards,
    Ulises
    public class CmdTest {     
    public static void main(String[] args) throws java.io.IOException {
    String outFile = "./ds8300/lsvogrp.txt";
    PrintWriter bout = null;
    try {
    bout     = new PrintWriter(                         new FileWriter(new File(outFile)));     
    } catch (IOException e) {
         e.printStackTrace();
    Runtime run = Runtime.getRuntime();
    run.traceMethodCalls(true);
    Process proc2 = run.exec("cmd /c dscli -user user -passwd psw" + "lsvolgrp -l");
    BufferedWriter ot = new BufferedWriter(
    new OutputStreamWriter(proc2.getOutputStream()));
    BufferedReader br = new BufferedReader(
    new InputStreamReader(proc2.getInputStream()));
    BufferedReader er = new BufferedReader(
    new InputStreamReader(proc2.getErrorStream()));
    try {
    String s;
    while((s=br.readLine())!=null) {
         System.out.println(""+s);
         bout.println(s);
    while((s=er.readLine())!=null) System.out.println("ERR:"+s);
    bout.close();
    System.exit(0);
    }catch (Exception ie) { //catch (InterruptedException ie) {
    System.out.println("Interrupted:"+ie.getMessage());}
    }

    Seems like the same question you asked last year.
    http://forum.java.sun.com/thread.jspa?threadID=5181153&messageID=9705196#9705196
    The proper way to design software is to start at the beginning and design Classes. Not try to butcher that which is working.
    You're running work outside the JVM and this work might interfere with other, similar work (the multi-threading issue.)
    I'd start with paper and pencil and see what conflicts might arise.

  • Need help w/ created classes and objects

    I am having a difficult time understanding what is wrong w/ my classes and objects. I've looked in two books and have messed around a bit. Here is what I am -attempting- to do.
    I want to make a class called CLOTHING. In this class i want objects such as shirt and pants (for now).
    these are the errors im getting:
    .\Shirt.java:6: invalid method declaration; return type required
         public Shirt(int size){
                   ^
    .\Shirt.java:3: class Clothing is public, should be declared in a file named Clothing.java
    public class Clothing {
           ^
    MyClassHW.java:10: cannot resolve symbol
    symbol  : constructor Shirt  (int,int)
    location: class Shirt
              myShirt = new Shirt(1,1);
                              ^
    3 errors------------------------------------------------------------
    This is the code for my Clothing class:
    import java.awt.*;
    public class Clothing {
         private int shirtSize;
         private void Shirt(Graphics s, int h, int v){
         Polygon shirts;
              shirts = new Polygon();
              shirts.addPoint(5+h,8+v); // 1
              shirts.addPoint(17+h,12+v); // 2
              shirts.addPoint(19+h,13+v); // 3
              shirts.addPoint(33+h,8+v); // 4
              shirts.addPoint(37+h,13+v); // 5
              shirts.addPoint(25+h,20+v); // 6
              shirts.addPoint(25+h,28+v); // 7
              shirts.addPoint(15+h,28+v); // 8
              shirts.addPoint(15+h,20+v); // 9
              shirts.addPoint(1+h,12+v); //10
              s.fillPolygon(shirts);
    }from what i understand each object is essentially a method...
    Here is the code for the java applet I'm making:
    import java.awt.event.*;
    import java.awt.*;
    import java.applet.*;
    public class MyClassHW extends Applet { // implements ActionListener, AdjustmentListener {
         Shirt myShirt;
         int size;
         public void init(){
              myShirt = new Shirt(1,1);
    // <applet code = "MyClassHW.class" height = 300 width=300> </applet>thank you for your time and help. as always, your efforts are appriciated.

    .\Shirt.java:6: invalid method declaration; return type required     public Shirt(int size){
    I guess, public Shirt(int size) is constructor in class shirt. You have one int in this constructor. Shirt(int size)
    Here you initialize your shirt with two int:
    MyClassHW.java:10: cannot resolve symbolsymbol : constructor Shirt (int,int)location: class Shirt          myShirt = new Shirt(1,1);
    Shirt(int size, int what?)
    It's why it show such message.
    But even if you fix it seems like you have very vague ideas about what you are doing.
    As far as I understood you need three classes.
    First applet Clothing:
    public class Clothing extends Applet{
    Shirt myShirt;
    Pants myPants;
    public void init() {
    myShirt = new Shirt(1); // small shirt
    myPants = new Pants(32, 40); // medium waist and long legs
    Second and third your classes Shirt and Pants:
    public class Shirt extends Object {
    int size;
    public Shirt(int s) {
    size = s;
    public int getSize () {
    return size;
    same for Pants, only you need two parameters for it or whatever you want.
    You could design it diffrently if you want derive your Shirts and Pants from Clothing and then to use them in your applet. But, indeeed, you desperately have to do some serious reading, where authors are accurate in they definitions and stuff, because it's kind of complicated.

  • Need help about career life

    Hi All,
    Em..i just need some advice about choosing correct career path.I graduated with a first class in IT with business information science in 2009. In 2009 after looking for jobs for few months i took a manager post in a petrol station which i never wanted.(Due to the credit crunch & the Family financial reasons) .Then unfortunately i had to stay out of work for 18months due to a serious spinal code operation i had to face.now in 2011 July im fit & ready to start my life again. but im lost where to start/ which career path to choose. (i've still got the job at the petrol station as the manager)
    ive liked data base management subject when i was in the University so, Ive been reading OCA-051 & interested on OCA qualification I just want to know what are the possible jobs i can apply if i get the certification? Basically what should i do to get any IT related job? :( ( i dont like programming)..
    Please be kind to reply.
    ps:i live in the Uk.
    Thanks.

    872882 wrote:
    Hi All,
    Em..i just need some advice about choosing correct career path.I graduated with a first class in IT with business information science in 2009. In 2009 after looking for jobs for few months i took a manager post in a petrol station which i never wanted.(Due to the credit crunch & the Family financial reasons) .Then unfortunately i had to stay out of work for 18months due to a serious spinal code operation i had to face.now in 2011 July im fit & ready to start my life again. but im lost where to start/ which career path to choose. (i've still got the job at the petrol station as the manager)
    ive liked data base management subject when i was in the University so, Ive been reading OCA-051 & interested on OCA qualification I just want to know what are the possible jobs i can apply if i get the certification? Basically what should i do to get any IT related job? :( ( i dont like programming)..
    Please be kind to reply.
    ps:i live in the Uk.
    Thanks.You'll sit on your bum and ruin your back again with most IT jobs. With your government shrinking, OCA qualification won't have much worth unless you personally know someone in the private sector that needs help. An operator job with your petrol company (assuming it's not just a mom 'n pop station) would probably require heavy lifting.
    IT is a good, solid, growing career path, but most of the work is still programming, and most ways up to better jobs go through that experience. You might be an exception if you have a way to join other skills with your IT education, such as business analysis or sales or web prettyfying. Perhaps the determinants are your personality and goals.
    I know, it's tough, but if you are honest with yourself and check out some of the "what color is my parachute" kinds of career advice books, you can find a happy medium. There actually are some benefits in starting a career during economically troubled times, but you only see that in retrospect. You have to decide on goals, pursue them vigorously, and reevaluate when it doesn't work for you.

  • NEED HELP about file handling and searching

    Hi guys !!!!!!!!!!!!!!
    A) I need a help from u i wrote this programme to read from the file and assign the lines for the string array.
    import java.io.*;
    public class ReadFile{
    public static void main(String[] args){
    int i;
    BufferedReader file;
    String line() = null;
    String fileName = "xx.txt";
              try {
                   file = new BufferedReader(new FileReader(fileName));
    for(i=1;i<=10;i++){
    line(i)= file.readLine();
    System.out.println(line(i));
    file.close();
              } catch (FileNotFoundException e) {
                   System.out.println("File: " + fileName + " not found.");
              } catch(IOException e) {
                   System.out.println("Error reading data from file: " + fileName);
    the thing is it is compiling but when interpritting it gives the error
    Exception in thread "main" java.lang.NullPointerException in line(i)= file.readLine();
    plese help me on this and
    B) i want to know how to search the string array to find 4 letter words.
    i'm taking the each element which is line(i) one at a time and search it.
    Plese help me on these issues !!!!!!!!!!!!!!!!!!!!!

    You try to create an array with line(i) (as far as i see) but you dont need to keep each line in memory. As far as i understand you just need to process lines sequentially.. (Null pointer exception is thrown because you did not create your array properly!)
    Look at this code:
    http://www.java-tips.org/java-se-tips/java.io/reading-text-from-a-file.html
    You just need to define process method in that code. (and of course try to understand). So as far as i see, you will check for 4-letter words inside process method!
    For detecting 4-character word, you need to extract the words in the line using StringTokenizer:
    http://www.java-tips.org/java-se-tips/java.util/how-to-use-stringtokenizer.html
    Then you can just just use length() method of String class:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html
    And if you need more advanced logic for processing the lines(currently seems to be the length of strings), you may try regular expressions:
    http://java.sun.com/docs/books/tutorial/essential/regex/index.html
    http://www.java-tips.org/java-se-tips/java.util.regex/

Maybe you are looking for

  • Services in transaction sicf failing with Internal Error 500

    Hi all, When I try to test a service in transaction sicf, by right clicking on it and saying Test service. I am getting an error "HTTP 500 Internal Server Error". All the services are running fine in smicm. The version of SAP is ECC 5.0(only ABAP Sta

  • Beginning of display Repair

    Well I too am the owner of a 17" matte MBP display that has the uneven backlighting. Specifically the bright bar at the bottom of the screen (about 1 inch) and then on the left and right hand sides of the screen dark shadows. I even have small dark t

  • How do I remove McAfee Site Advisor from OS 10.7.5?

    I cancelled the McAfee Security Suiteweeks ago but the site advisor is still active and blocks sites such as Angie's List even when you tell it to enter anyhow. I suspect that it causes erratic screen moving and slows the computer. I have dragged it

  • Authorization details for T.Code PA61& PA71.

    Hi All Experts, We have to give access to user with T.Code PA61 & PA71 for creating IT2001 & IT2010. Here we want to give the "Create"authorization only and not any another. (like change, Delete, Copy) We tried on object p_orgin with authorization Le

  • ITunes screensaver broken

    A couple of weeks ago, my iTunes screensaver broke. It says my iTunes doesn't have any cover art. (But I do.) Mac OS X 10.7.2. My iTunes library is on an external USB drive. It otherwise functions normally. I can play anything from the library, see c