I´m new in programming and have to do some homework but I´m stuck. I need to do this:
As a developer, write a program to search a string entered by a user from the array of strings.
Background of the problem statement: You have an array of email IDs of employees. As a programmer, write a program to search the email ID entered by a user.
I have my ArrayList but now I want to be able to enter an email address in the console & the program should check if the entered e-mail address is in my Array List. Can somebody please help me, I couldn't find anything like that (maybe also I don't know how to search for my answer) I´m happy for any help!
instead of searching for the element in the syntax like I did here, I want to have the system asking the user for the email ID and search my ArrayList for it. if the email ID is in the Array List the output should be: "email ID" + searcElement + "found" otherwise "email ID" + searcElement + "not found"
package searchElement;
import java.util.ArrayList;
public class searchElement {
public static void main(String[] args) {
ArrayList<String> emailID = new ArrayList<String>();
emailID.add("simon.hasler@gmx.com");
emailID.add("leonie.klein@gmx.com");
emailID.add("lea.hoch@gmx.com");
emailID.add("max.neumann@gmx.com");
emailID.add("henrik.fiesler@gmx.com");
emailID.add("laura.kramm@gmx.com");
emailID.add("sabine.neuwirth@gmx.com");
String searcElement = "simon.hasler@gmx.com";
for(int i=0; i<emailID.size(); i++) {
System.out.println(emailID.get(i));
if(searcElement==emailID.get(i)) {
System.out.println("\n");
System.out.println("email ID" + searcElement + "found");
break;
}
}
}
}