0% found this document useful (0 votes)
2 views1 page

Java

The Java program uses a Vector to store a list of strings input by the user. It allows the user to add an initial number of strings and then checks if a new string is present in the vector, either deleting it if found or adding it if not. Finally, it displays the updated vector of strings.

Uploaded by

guptavipul2726
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Java

The Java program uses a Vector to store a list of strings input by the user. It allows the user to add an initial number of strings and then checks if a new string is present in the vector, either deleting it if found or adding it if not. Finally, it displays the updated vector of strings.

Uploaded by

guptavipul2726
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;
import [Link];

public class StringVector {


public static void main(String[] args) {
Vector<String> stringVector = new Vector<>();
Scanner sc = new Scanner([Link]);
[Link]("Enter the number of strings you want to add initially: ");
int n = [Link]();
[Link]();
for (int i = 0; i < n; i++) {
[Link]("Enter string " + (i + 1) + ": ");
String input = [Link]();
[Link](input);
}
[Link]("Initial vector: " + stringVector);
[Link]("Enter a new string to check: ");
String newString = [Link]();

if ([Link](newString)) {
// If the string is present, delete it
[Link]("String '" + newString + "' is present. Deleting it...");
[Link](newString);
} else {
// If the string is not present, add it
[Link]("String '" + newString + "' is not present. Adding it...");
[Link](newString);
}
[Link]("Updated vector: " + stringVector);
}
}

You might also like