Hi guys
i have a problem. how i can do a search in a array list?
i need a method that search in arraylist
I have this code
Code:private static void up() {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Your name");
String nconta = sc.next();
//incomplete
}
//he should access the arraylist with an itenerator
public static void ShowAll() {
// TODO Auto-generated method stub
CurrentAccount conta1 = new CurrentAccount("Alberto Carlos", 1052);
CurrentAccount conta2 = new CurrentAccount("Pedro Fonseca", 30);
CurrentAccount conta3 = new CurrentAccount("Ricardo Vitor", 1534);
CurrentAccount conta4 = new CurrentAccount("João Lopes", 3135);
List<CurrentAccount> lista = new ArrayList<CurrentAccount>();
lista.add(conta1);
lista.add(conta2);
lista.add(conta3);
lista.add(conta4);
Collections.sort(lista);
Code:System.out.printf("Bank Accounts:" + "%n");
Iterator<CurrentAccount> itr = lista.iterator();
while (itr.hasNext()) {
CurrentAccount element = itr.next();
System.out.printf(element + " " + "%n");
}
System.out.println();
if i fallow the same logic (iterator like above) in the method up (), it does a error. I think it is because the arrayList is not being instantiated.
so, the problem is that i can't acess to the arraylist, my ideia is doing a search for an account, if it exists, show respective account in console
i really need help
thanks in advice
