Here is my customer.csv file:
1, Ali,1203456789, Normal
2, Siti,134567890, Normal
3, Bob,1568980765, Normal
I want to change the Normal status of the name I enter to Cased but my code seems got something wrong.And here is my code:
public static void main(String[] args) throws IOException{
Scanner input = new Scanner(System.in);
System.out.println("Please enter the customer you want to flag as Cased:");
String flagCus = input.nextLine();
ArrayList<String> customersFlagged = new ArrayList<String>();
List<String> lines = Files.readAllLines(Paths.get("customer.csv"));
for (int i = 0; i < lines.size(); i++) {
String[] items = lines.get(i).split(",");
if (items[1] == flagCus){
String enterList = items[0] + "," + items[1] + "," + items[2] + "," + "Cased";
customersFlagged.add(enterList);
} else{
String enterList = items[0] + "," + items[1] + "," + items[2] + "," + items[3];
customersFlagged.add(enterList);
}
}
I think the problem is the line if (items[1] == flagCus) ones but I am not sure where got wrong , I have been try to add a " " before my flagCus when doing the if statement but it still goes wrong. Can somebody help me check this code? Thank you for your attention.
Edit:I should have change the code (items[1] == flagCus) to (items[1].equals(" " + flagCus).Thank you guys for help.