Hi,
I created a text file in which has the data likes name, sex and age.
Tom, M, 23
Mary, F, 29
Peter, M, 30
.......
Vector vector = new Vector();
String string = ""; while ((string = in.readLine()) != null ) { StringTokenizer st = new StringTokenizer(string, " "); String name = st.nextToken(); String sex = st.nextToken(); String age = st.nextToken(); vector.add(new Data(name, sex, age));
So, the data in text file will be read to a Data class which has 3 String variables.
Here is the Data class:
public class Data { private String name; private String sex; private String age; public Data(String a, String b, String c){ name = a; sex = b; age = c; } public String toString(){ return(name + " " + sex + " " + age); }}
So, the vector array store each object for each line of record now. Problem occurs.
How can I only print out the name of 3rd line (for example) only, how can I print out name and age of 5th line of record?
When I System.out.println((Data)vector.elementAt(i)) - here has a for loop, it print out the whole line of record becasue I override the String object in the Data class.
However, I need to do a keyword search by name, sex, age and wildcard for them.
When I am using the following code in a for loop to do a search, it cannot find the matching.
vector.elementAt(i).toString().equalsIgnoreCase(consoleinput)
How should I do it?
Thanks for any advice.
Andrew