Translate this code from C# to Java.
class HelloWorld { static void Main() { List packets = new List(); packets.Add(1); packets.Add(2); packets.Add(3); packets.Add(4); packets.Add(5); // packets.Add(89); packets.Add(48); packets.Add(14);// packets.Add(4); packets.Add(5); //packets.Add(2); packets.Add(2); packets.Add(1); packets.Add(5); packets.Add(3); //packets.Add(1); packets.Add(89); // packets.Add(48); //packets.Add(14); // packets.Add(1); // I/P - 1,2,3,4,5, channels - 2 ---> O/P - 7 // I/P - 2,2,1,5,3, channels - 2 ---> O/P - 7 // I.P - 89,48,14 channels = 3 ---> O/P - 151 int channels = 2; long result = maximumQuality(packets, channels); Console.WriteLine(result); } private static long maximumQuality(List packets, int channels) { if (packets == null || packets.Count() == 0) return 0L; if (packets.Count() == 1) return (long) packets[0]; if (channels <= 0) { // TODO.. throw exception, bad input } packets = packets.OrderBy(x => x).ToList(); int n = channels - 1; int median = 0; while (n-- > 0) { int val = packets[packets.Count()-1]; median += val; packets.RemoveAt(packets.Count()-1); } long result = findMedian(packets, median); return result; } private static long findMedian(List list, long median) { long val = 0; if (list.Count() %2 == 0) { // val = (long) (list[list.Count()/2] + list[list.Count()/2 - 1])/2; val = (long) Math.Ceiling((((double)list[list.Count()/2] + (double)list[list.Count()/2 - 1]))/2); } else { val = (long) list[list.Count()/2]; } return (long) (val + median); } }