Solved

vector of strings

Posted on 2002-07-16
3
606 Views
Last Modified: 2012-08-13
Hi All,
I would like to create two different vectors. One vector will hold integers and the other will hold strings.

I would like to add to the size of each vector as I see more elements worth saving.

Could someone please give me sample code how to do this and some good web sites that give lots of java sample code? Sun is too theoretical.

TIA DoughBoy
0
Comment
Question by:DoughBoy
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
kylar earned 50 total points
ID: 7157807
import java.util.*;

public class VectorSaver{
 
 public VectorSaver(){
    Vector stringVector = new Vector();
    Vector intVector = new Vector();
     String s1 = new String("String 1");
     String s2 = new String("String 2");
     Integer i1 = new Integer(0);
     Integer i2 = new Integer(99);
     stringVector.add(s1);
     stringVector.add(s2);
     intVector.add(i1);
     intVector.add(i2);

    System.out.println("String Vector:"+stringVector.toString());
    System.out.println("Int Vector:" + intVector.toString();

 }


public static void main(String[] args){
 new VectorSaver();

}
}

Cheers,
Kylar
0
 

Author Comment

by:DoughBoy
ID: 7157848
Thanks Kylar,
BTW, do you have any recommended good web sites?
What method gets the new size of the vector?
0
 
LVL 4

Expert Comment

by:kylar
ID: 7157858
I use the Java API docs almost exclusively. They are availible for download at sun's site.. or can be viewed online at

http://java.sun.com/j2se/1.3/docs/api/

Look up Vector and you'll see under method description the call size() that returns the size of the vector.

As to good websites, I usually just search on google.com if there's something I specifically need. If you're just getting started, Bruce Eckel's book 'Thinking In Java' is very very good, and availible online.. do a search for it.



Cheers,
Kylar
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java Timer (static) 9 36
ForLoop Example 3 40
map related example 6 38
javap not working 8 39
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now