In general, I agree with the split
method in the previous answer, but when returning the first line, the substring method is the same amount of work for the programmer (and, for insanely large lines, less computational work):
String result = names.substring(0, names.indexOf('-'))
source share