How to check if a client already exist in array in java

Newbie here.

I just want to ask, how to disallow someone to enter the same element in an array?

this is my code currently and it's not working properly:

import java.util.*;

public class Main {

public static void main(String[] args) {

Scanner input=new Scanner(System.in);

String[] username=new String[5];

for (int c=0;c<5;c++)

{

System.out.print("Enter client name: ");

username[c]=input.nextLine();

if (username.equals(username[c]))

{

System.out.println("The client already exist.");

}

}

}

}

p.s. I hope you guys can help me....

Read More »

By: StackOverFlow - 5 days ago

Related Posts