import java.util.*;
import java.io.*;

class Ideone {
    public static String join(List<String> msgs) {
    	int size = msgs == null ? 0 : msgs.size();
        return size == 0 ? "" : size == 1 ? msgs.get(0) : msgs.subList(0, --size).toString().replaceAll("^.|.$", "") + " and " + msgs.get(size);
    }

	public static void main (String[] args) throws Exception {
        System.out.println(join(null));
        System.out.println(join(Arrays.<String>asList()));
        System.out.println(join(Arrays.asList("one")));
        System.out.println(join(Arrays.asList("one", "two")));
        System.out.println(join(Arrays.asList("one", "two", "three")));
	}
}