Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Adding a String array to Vector dynamically  (Read 2370 times)
0 Members and 1 Guest are viewing this topic.
deAppel
Favorite member
Member
*

Reputation: 0
HappyFace plants one on you
Offline Offline
Posts: 45
Referrals: 0

Awards
« on: July 14, 2007, 10:20:18 AM »

Code
GeSHi (java):
  1. import java.util.Vector;
  2.  
  3.  
  4. /*--------------------------------------------------------------------------
  5. //Author List:
  6. //   deAppel <Creator>
  7. //
  8. //Description:
  9. // Example of adding a String array dynamically
  10. //
  11. //Environment:
  12. //   This software was developed using Eclipse and Java 1.6
  13. //
  14. //Copyright Information:
  15. //   Copyright (C) 2007      <Institution><None>
  16. // Ark de Appel www.engineeringserver.com
  17. //
  18. //----------------------------------------------------------------------*/
  19.  
  20. public class AddElements{
  21. String[] str = {"This" , "is", "a" , "string", "extraString", "anotherOne"};
  22. Vector v1, v2;
  23.  
  24. public void Demo(){
  25. System.out.println("Adding elements manually to the vector: ");
  26.  
  27. v1 = new Vector();
  28. v1.add("This");
  29. v1.add("is");
  30. v1.add("a");
  31. v1.add("String");
  32. System.out.println( "" + v1);
  33.  
  34. System.out.println();
  35. System.out.println("Adding elements dynamically to the vector: ");
  36.  
  37. v2 = new Vector();
  38.  
  39. for (int i = 0; i < str.length; i++){
  40. v2.add(str[i]);
  41. }
  42.  
  43. System.out.println(""  + v2);
  44. }
  45.  
  46. public static void main(String[] args){
  47. AddElements AE = new AddElements();
  48. AE.Demo();
  49. }
  50. }
Created by GeSHI 1.0.7.20

Output:
Adding elements manually to the vector:
[This, is, a, String]

Adding elements dynamically to the vector:
[This, is, a, string, extraString, anotherOne]

Logged

Earn $0.04 or more for each search you make! http://www.myhpf.co.uk/apply001.asp?Friend=77889

If you need homework help, just post your assignment and i'll code it before your deadline =) i'll provide you "t3h c0d3z" but only if you show me that you have done something and not just ask for me to write everything for you. Just tell us what the problem is and i'm sure we can fix it for you!

I was born into the Hakka lineage, A bloodline that
traces it's roots back to the original Han emperors of
China. During the rise of the 3 Kingdoms (China's
famous warring period), the Hans were overthrown
and exiled. Forced to flee, they headed south finding
refuge within the mountains of Guilin Province where
they lived under their new title, the Hakka and patiently
wait for their chance to return to the throne as the
Sons Of Heaven...
Croco
Staff
Member
*

Reputation: 1
Offline Offline
Gender: Male
Posts: 64
Referrals: 0

Awards
« Reply #1 on: November 09, 2007, 02:45:39 PM »

nice example ...
Logged
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #2 on: November 13, 2007, 04:04:06 PM »

nice example ...

Thanks, im just waiting for people to come here to ask questions so I can help them out ;/
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here