title: How to create Spark broadcast variable from Java String array?
body: <p>I have Java String array which contains 45 string which is basically column names </p>
  
  <pre><code>String[] fieldNames = {"colname1","colname2",...}; 
  </code></pre>
  
  <p>Currently I am storing above array of String in a Spark driver in a static field. My job is running slow so trying to refactor code. I am using above String array while creating a DataFrame </p>
  
  <pre><code>DataFrame dfWithColNames = sourceFrame.toDF(fieldNames); 
  </code></pre>
  
  <p>I want to do the above using broadcast variable to that it don't ship huge string array to every executor. I believe we can do something like the following to create broadcast </p>
  
  <pre><code>String[] brArray = sc.broadcast(fieldNames,String[].class);//gives compilation error 
  
  DataFrame df = sourceFrame.toDF(???);//how do I use above broadcast can I use it as is by passing brArray 
  </code></pre>
  
  <p>I am new to Spark.</p>