I have a text file with the data as shown below as an example..
2;30;1;801;2;1951;195102;1111;
2;30;1;801;3;1621;162101;1111;
2;30;1;802;1;1807;180702;1111;
2;30;1;802;1;1807;180703;1111;
2;30;1;802;1;1807;180704;1111;
2;30;1;802;2;1101;110101;1111;
2;30;1;802;2;1139;113902;9999;
2;30;1;802;2;1948;194801;1111;
2;30;1;802;2;1948;194802;1111;
2;30;1;802;3;2477;247701;1111;
2;37;2;803;1;2006;200601;0000;
2;37;2;803;1;2006;200602;0000;
2;37;2;803;2;2005;200501 ;0000;
In my program I have to put a filter and then display, which groups the Rows i.e. Row[3]
based on Row[7]
. My list should appear like this after filtering for example only for 802
802;1;1807;180702;1111;
802;1;1807;180703;1111;
802;1;1807;180704;1111;
802;2;1101;110101;1111;
802;2;1139;113902;9999;
802;2;1948;194801;1111;
802;2;1948;194802;1111;
802;3;2477;247701;1111;
similarly for 803
803;1;2006;200601;0000;
803;1;2006;200602;0000;
803;2;2005;200501 ;0000;
The problem is the value of Row[3]
is not constant and keeps varying throughout the file in a group for example a bunch of values are 802, the next bunch 804, 806 etc and so on. which should be grouped like as shown above.
I already have a FileReader
for reading the file, but can anyone tell me a logic on how to go about applying this filter?
code for reading file and placing values in a list
public ArrayList<Asset> getData() {
ArrayList<Asset> list = new ArrayList<Asset>();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
Asset sd = null;
while ((line = reader.readLine()) != null ) {
String[] RowData = line.split(";");
if (RowData.length >= 19) {
sd = new Asset();
sd.setProductID(RowData[3]);
sd.setProductName(RowData[7]);
sd.setStatus(RowData[13]);
list.add(sd);
}
}
return list;
}
I am confused as to what logic to add in order to filter RowData[3]
in the while
loop while reading from the reader