• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing Parts of String Arrays

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

its me again with another question.

I am trying to program a PhoneBook at the moment and I got stuck at a specific part.
When I want to search my PhoneBook I need to compare the LastNames and FirstNames but I am not sure how I can access the information.

The entries are safed in an array in the following form:



Know I when I want to write an algorithm which looks for the last name (second entry) first and the first name second I am not sure how I can access the information...

How can i get for example entries[0]firstName only or lastName only?

Thank you very much for the help.
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you have getFirstName(), and getLastName(), and getPhoneNumber() methods. You can iterate the array:
 
Michael Grünau
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, i have!

Thats perfect, thanks for the solution!!!
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a pleasure
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternative, using the Java8+ constructs:-Afraid I haven't got the time to explain everything in detail. I have decided to use a PhoneNumber class rather than using Strings for the phone number.
 
reply
    Bookmark Topic Watch Topic
  • New Topic