Computer Science Canada Search Arrays? |
Author: | Shiro786 [ Mon Jun 11, 2007 4:22 pm ] | ||
Post subject: | Search Arrays? | ||
Hey! Sorry to bug everyone again, but it's me, Shiro with some more Novice questions. ![]() Please consider the following (Bill Nye FTW >_>):
(Think of c.println as System.out or whatever, I was taught this type of Java differently cause my teacher is a stoner.) And so, how am I to search through the arrays for a student name? I would like to print it after as it is required to by same said teacher. Thanks in advance![/quote] |
Author: | Ultrahex [ Mon Jun 11, 2007 5:28 pm ] | ||
Post subject: | Re: Search Arrays? | ||
The easiest way is to loop through each name in the array, and check whether it is equal to the name you are looking for for example this code looks for the name Jim in the names String Array
|
Author: | Shiro786 [ Mon Jun 11, 2007 6:53 pm ] |
Post subject: | Re: Search Arrays? |
Wish I saw your post 2 hours ago. Fortunately, I found out how to do it in the end! I totally forgot that == just compares strings. Thanks for your help man. And thanks to everyone else who have helped me thus far. ![]() |