You are on page 1of 5

JAVA

ASSIGNMENT

NAME: Soham Sandip Purao


Roll no. A051
BRANCH: AIML
SAP ID: 60017230003
BATCH: A2

NAME: Soham Sandip Purao ROLL NO: A051 SAP ID: 60017230003
NAME: Soham Sandip Purao ROLL NO: A051 SAP ID: 60017230003
NAME: Soham Sandip Purao ROLL NO: A051 SAP ID: 60017230003
Aim: To implment collections (ArrayList/Vectors)
Code : 4.b WAP to add n strings in a vector array. Input new string and check if it is present in the vector.
If present delete it else add to the vector

import java.util.*;
class StrVec
{
public static void main(String args[])
{
int n = 20 ,index;
Scanner in = new Scanner(System.in);
String s,temp;
Vector<String> st = new Vector<String>(n);
System.out.println("Enter a string:");
s = in.nextLine();
for(int i=0;i<s.length();i++)
{
st.add(s[i]);
}
System.out.println("The vector is :"+s);
System.out.println("Enter another string");
temp = in.nextLine();
if(st.contains(temp))
{
st.remove(st.indexOf(temp));
}
else
{
st.add(temp);
}
}
}

NAME: Soham Sandip Purao ROLL NO: A051 SAP ID: 60017230003
Output:

Conclusion: Understood the Collection Frameworks in Java and learnt to implement the ArrayList and
Vector Collections

NAME: Soham Sandip Purao ROLL NO: A051 SAP ID: 60017230003

You might also like