code: def _new_java_array(pylist, java_class):
          
          sc = SparkContext._active_spark_context
          java_array = None
          if len(pylist) > 0 and isinstance(pylist[0], list):
              # If pylist is a 2D array, then a 2D java array will be created.
              # The 2D array is a square, non-jagged 2D array that is big enough for all elements.
              inner_array_length = 0
              for i in xrange(len(pylist)):
                  inner_array_length = max(inner_array_length, len(pylist[i]))
              java_array = sc._gateway.new_array(java_class, len(pylist), inner_array_length)
              for i in xrange(len(pylist)):
                  for j in xrange(len(pylist[i])):
                      java_array[i][j] = pylist[i][j]
          else:
              java_array = sc._gateway.new_array(java_class, len(pylist))
              for i in xrange(len(pylist)):
                  java_array[i] = pylist[i]
          return java_array
docs: Create a Java array of given java_class type. Useful for
          calling a method with a Scala Array from Python with Py4J.
          If the param pylist is a 2D array, then a 2D java array will be returned.
          The returned 2D java array is a square, non-jagged 2D array that is big
          enough for all elements. The empty slots in the inner Java arrays will
          be filled with null to make the non-jagged 2D array.
  
          :param pylist:
            Python list to convert to a Java Array.
          :param java_class:
            Java class to specify the type of Array. Should be in the
            form of sc._gateway.jvm.* (sc is a valid Spark Context).
          :return:
            Java Array of converted pylist.
  
          Example primitive Java classes:
            - basestring -> sc._gateway.jvm.java.lang.String
            - int -> sc._gateway.jvm.java.lang.Integer
            - float -> sc._gateway.jvm.java.lang.Double
            - bool -> sc._gateway.jvm.java.lang.Boolean