Q:

Reverse Names Given

I'm looking to reverse the names found in a list given to me (EDIT: given to me from a web scrapping of a website) Again not homework
Small sample of list:
Baynes, Aron
Bazemore, Kent
Beal, Bradley
Beasley, Malik
Beasley, Michael
Belinelli, Marco
Bell, Jordan
Bembry, DeAndre'

I need them as Aron Baynes (or Aron,Baynes)
Weirdly people think this is homework problem. THIS IS NOT. I am using NBA player names in a program I have written. I can not post code as the code used is 1000s of lines long. I simply need the ability to reverse the name order in a quick manner compared to my attempts
What I tried: for loops using , as a index then working back and forth using substrings. This did not work well for a list of strings as given above

A:

If you have all names in file (e.g. names.txt):
Baynes, Aron
Bazemore, Kent
Beal, Bradley
Beasley, Malik
Beasley, Michael
Belinelli, Marco
Bell, Jordan
Bembry, DeAndre'

You can:

Read line
split line (using separator)
display in reverse way

import java.io.BufferedReader;
import java.io.FileReader;

public class Main {

    public static void main(String[] args) {

        // File name
        String fileName = "names.txt";
        String separator = ", ";

        String line;

        try (FileReader fileReader = new FileReader(fileName);
             BufferedReader bufferedReader = new BufferedReader(fileReader)) {

            while ((line = bufferedReader.readLine()) != null) {
                String[] elements = line.split(separator);

                if (elements.length == 2) {
                    System.out.printf("%s %s\n", elements[1], elements[0]);
                } else {
                    System.out.println("Wrong line: " + line);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Or using List instead of files:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>(Arrays.asList(
                "Baynes, Aron",
                "Bazemore, Kent",
                "Beal, Bradley",
                "Beasley, Malik",
                "Beasley, Michael",
                "Belinelli, Marco",
                "Bell, Jordan",
                "Bembry, DeAndre'"
        ));

        String separator = ", ";

        // Using loop
        for (String person : list) {
            String[] elements = person.split(separator);

            if (elements.length == 2) {
                System.out.printf("%s %s\n", elements[1], elements[0]);
            } else {
                System.out.println("Wrong line: " + person);
            }
        }

        // Using stream
        list.forEach(person -> {
            String[] elements = person.split(separator);

            if (elements.length == 2) {
                System.out.printf("%s %s\n", elements[1], elements[0]);
            } else {
                System.out.println("Wrong line: " + person);
            }
        });
    }
}

