# Program to add n string in a Vector Array

- Link: https://technotaught.com/program-to-add-n-string-in-a-vector-array/
- Published: 2018-11-07T15:29:12+05:30
- Author: Ashishkumar Vishwakarma

In this we will learn how to add n string in a Vector Array in java

## Program to add n string in a Vector Array

WAP TO ADD N STRINGS IN A VECTOR ARRAY. INPUT NEW STRING S AND CHECK WHETHER IT 
PRESENT IN THE VECTOR. IF PRESENT DELETE IT OR ADD ANOTHER VECTOR.

Also, you can use the Java [compiler](https://www.onlinegdb.com/online_java_compiler)
to compile a program.

##### Source code

    ```c
    import java.util.*;
    class vector
    {
    	public static void main(String args[])
    	{
    		Vector c= new Vector();
    		Scanner s=new Scanner(System.in); // CREATE OBJECT

    		int n;
    		String name;
    		int choice;
    		do{
    	      System.out.println("1.insert\n2.delete\n3.display\nEnter 
                  ur choice");
    	      choice=s.nextInt();
    			switch(choice)
    			{
    				case 1:  for(int i=1;i<=3;i++)
    					{

                                         System.out.println("Enter city");
    						name=s.next();								     		
                                             if(c.contains(name))
    					{
    					   System.out.println("City is 
                                                     already exist");
    					}
    					else
    					{
    					 c.addElement(name);
    					}
    					}
    					break;
    				case 2: System.out.println("Enter 
                                            city");
    					name=s.next();
    					if(c.contains(name))
    					{
    					  c.remove(name);
    					}
    					else
    					{
    					    System.out.println("city 
                                             doesnot exist");
    					}
    					break;
    				case 3: 
    					Enumeration nam =c.elements();
    					System.out.println("cities");
    					while(nam.hasMoreElements())
    			    System.out.println(nam.nextElement()+" ");
    					 System.out.println(" \n");
    					break;
    			}// END OF SWITCH
    			System.out.println("1.yes\n2.no\n");	
    			n=s.nextInt();
    		}while(n==1);
    	}// END OF MAIN
    } // END OF CLASS
    ```

 

### Output.

> C:\A>javac vector.java
> C:\A>java vector insert delete display Enter ur choice 
> 1Enter cityUP Enter city MPEnter city MUMBAI DO YOU WANT TO CONTINUE yes 2 . no1
> 1 . insert delete display Enter ur choice 3citiesUPMP MUMBAIDO YOU WANT TO CONTINUE
> 1 .yes 2 . no 1
> insert 
> delete display Enter ur choice 2Enter cityUP DO YOU WANT TO CONTINUE yes
> no 1insert delete display Enter ur choice 3citiesMP MUMBAI

Also, View- [Write a java program to create a window using swing.](https://technotaught.com/22-write-a-java-program-to-create-a-window-using-swing/)

### Share this:

 * [  X ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=twitter)
 * [  Facebook ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=facebook)
 * [More](https://technotaught.com/program-to-add-n-string-in-a-vector-array/#)

 * [  WhatsApp ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=jetpack-whatsapp)
 * [  LinkedIn ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=linkedin)
 * [  Email ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?subject=%5BShared%20Post%5D%20Program%20to%20add%20n%20string%20in%20a%20Vector%20Array&body=https%3A%2F%2Ftechnotaught.com%2Fprogram-to-add-n-string-in-a-vector-array%2F&share=email)
 * [  Reddit ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=reddit)
 * [  Tumblr ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=tumblr)
 * [  Pinterest ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=pinterest)
 * [  Telegram ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/?share=telegram)
 * [  Print ](https://technotaught.com/program-to-add-n-string-in-a-vector-array/#print?share=print)

### _Related_

## Comments

### By: Anessa B

- Link: https://technotaught.com/program-to-add-n-string-in-a-vector-array/#comment-129
- Published: 2020-04-22T09:58:51+05:30

Incredible points. Sound arguments. Keep up the great work.
