I am trying to get the last element from the end of each line of my ArrayList/array.
For example i have these records int my list: (don't mind the language, Greek names)
Nikos Pappas : 321/2012999, C,8.53
Marios Athanasiou : 321/2012001, A,6.89
Stavroula Markou : 321/2011001, D,7.00
Giannis Kallogirou : 321/2009005, ST, 6.89
Nikoletta Stefanou : 321/2010001, D, 7.25
Stathis Petrou : 321/2011002, E, 8.10
Kostas Tzovalis : 321/2007667, C, 5.00
Michalis Kotsis : 321/2009723, D, 7.12
Maria Katsanou : 321/2012002, C, 5.50
And I want to take: 8.53, 6.89,....,5.50 (marks of students)
This is what I've made so far (the file is the file which contains the above info)
public static void main(String[] args) {
BufferedReader br = null;
ArrayList <String> list = new ArrayList <> ();
try
{
br = new BufferedReader(new FileReader("C:/Users/Stefi/Desktop/java_ask3.txt"));
String str;
//System.out.print("mpika");
while((str = br.readLine()) != null)
{
list.add(str);
System.out.println(str);
}
}
catch(IOException e)
{
System.out.println("Κάτι πήγε στραβά! Προσπάθησε πάλι.");
}
finally
{
try
{
if (br != null)
{
br.close();
}
}
catch(IOException e2)
{
System.out.println("Δεν μπορεσα να κλείσω το αρχείο.");
}
}
int x = list.size();
String [] array = new String[x];
array = list.toArray(array);
for(int i=0; i<array.length; i++)
{
System.out.println(array[i]);
}
String [] f = new String[list.size()];
String vathmos;
for(int i=0; i<array.length; i++)
{
vathmos = list.get(i).replaceAll("\\D+", "");
f[i] = vathmos;
}
System.out.println("\n\n\n Float Print\n");
for(int i=0; i<array.length; i++)
{
System.out.println(f[i]);
}
}
this is an example of my output:
3212012999853
3212012001689
3212011001700
3212009005689
It takes all the numbers it finds. But I don't know how to take only the last float number. I know it's totally wrong to work like this, and work like this because I'll never get the float i want.
I also tried to convert my list into array and take the last element but didn't work out.