im working a search method on a linked list this my code
Node item=head;
String help=item.getKonten();
System.out.printf("data to search");
search=input.nextLine();
while (help.compareTo(search)>0){
if (help.equals(search)){
System.out.println ("index " + index);
ktemu=1;
} else {
item=item.getLink();
bantu1=item.getKonten();
}
index++;
}
if (ktemu == 0){
System.out.println("data not found");
}
the output
data : 1,2,3,4,5
data to search 2
data not found
anyone can point me whre this code goes wrong so the index not shown up
compareTomethod returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.So when you compare 1 with 2 which return negative value and
-1>0becomes false. So it come out of loop.