This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Comparing Parts of String Arrays

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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: 68026
258
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i have!

Thats perfect, thanks for the solution!!!
 
Campbell Ritchie
Marshal
Posts: 68026
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure
 
Campbell Ritchie
Marshal
Posts: 68026
258
  • Mark post as helpful
  • send pies
  • 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.
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!