I doubt that there is something which can do that out of the box, especially since you seem to be missing the ID parameter in your Person object.
A possible solution could be to have a constructor in your Person class which takes a string as a parameter. This string would represent a line in your text file which the constructor would then deconstruct (.split("\\t") maybe?) and then initialize the proper values according to the string which you have passed.
EDIT: Seeing your comment, you could try and do something as suggesting in this previous SO post:
List<Person> pList = new ArrayList<Person>();
while (rs4.next()) {
pList.add(new Person(rs4.getString(0), rs4.getString(1)...);
}
...
return pList;
And for person:
package com.mirdb.model;
import java.util.Set;
public class Person {
private String ID;
private String fName;
private String lName;
private Set<String> moNumbers;
public Person(String id, String fName, String lName, Set<String> moNumbers)
{
this.ID = id;
this.fName = fName;
...
}
...
public String getID(){return this.ID;}
...
public boolean equals(object obj)
{
if (obj == null)
return false;
if (obj == this)
return true;
if (!(obj instanceof Person))
return false;
Person rhs = (Person) obj;
return rhs.getID().equals(this.getID());
}
}
EDIT: As per your other question: But question is how can I make Set<String> moNumbers so that I can pass it to constructor??
In your example you are only showing one masked number (at least that is what I think the * represent. If you have only one number, you could do this:
List<Person> pList = new ArrayList<Person>();
while (rs4.next()) {
Set<String> mobileNumbers = new HashSet<String>();
mobileNumbers.add(rs4.getString(3));
// if on the other hand you have multiple comma delimeted numbers, you could try the approach below:
//Set<String> mobileNumbers = new HashSet<String>(Arrays.asList(rs4.getString(3).split(",")));
pList.add(new Person(rs4.getString(0), rs4.getString(1), rs.getString(2), mobileNumbers);
}
return pList;
JavaCSVand come back with a concrete question.