Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

getters with collections

I am writing a  getPerson( ) that takes two parameters, an integer position and a flexible-size collection that holds Person references. The method returns a Person reference found in the collection at the specified position. It also has to implement a line of code checks the validity of the position parameter. After i do this i need overload it such that the new method takes only one parameter, a flexible-size collection that holds Person references I really stuck on how to implement this?
0
Johny24max
Asked:
Johny24max
  • 4
  • 4
1 Solution
 
objectsCommented:
How would the 2nd method know which element to return if its not passed the position?
0
 
Johny24maxAuthor Commented:
If the position parameter is not in the range 0 to last valid position in the collection, the method returns null
0
 
objectsCommented:
But aren't you saying the 2nd method will not have a position parameter.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Johny24maxAuthor Commented:
the second will not have a position parameter
0
 
objectsCommented:
So how will it determine what element to return?
0
 
Johny24maxAuthor Commented:
well  i really dont know? but i just really need to figure out how to a  getPerson( ) that takes two parameters, an integer position and a flexible-size collection that holds Person references. The method returns a Person reference found in the collection at the specified position. The position parameter is just a way on how you can improve the getPerson() method.
0
 
objectsCommented:
> but i just really need to figure out how to a  getPerson( ) that takes two parameters, an integer position and a flexible-size collection that holds Person references.

something like:

public Person getPerson(List people, int position)
{
     ...
0
 
Johny24maxAuthor Commented:
i did something like this is this valid?

public String getPerson(lint p1, int p2)
{
      return person;
}


0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> return person;

What's that? The 2 parameters are not being used.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now