title: How do I pass a 2d array into Java Main from ReactJS?
body: <p>I have two programs, one in ReactJS and one in Java, and need to pass a 2d array from ReactJS into my Java main, but didn't realise that I can't modify the main signature of <code>public static void main(String[] args) {}</code> to accept it.</p>
  
  <p>I've seen similar questions around, but they are mostly about passing multidimensional arrays around methods in general which are setup inside of the method, but need to pass in something like:</p>
  
  <p><code>[["1", "string", "1.0"], ["2", "string", "2.0"]]</code></p>
  
  <p>...but can't be sure what I need to get out. It'll only add to the string elements in the middle, so will be something like:</p>
  
  <p><code>[["1", "string", "string", "1.0"], ["2", "string", "string", "string", "2.0"]]</code></p>
  
  <p>So, just to reiterate, how can I pass in a 2d array (knowing how big the internal array will be), and return a 2d array (not knowing how big the internal arrays will be)?</p>
  
  <p>My Java class is as follows...</p>
  
  <pre><code>import edu.stanford.nlp.ling.CoreAnnotations;
  import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
  import edu.stanford.nlp.pipeline.Annotation;
  import edu.stanford.nlp.pipeline.StanfordCoreNLP;
  import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
  import edu.stanford.nlp.trees.Tree;
  import edu.stanford.nlp.util.CoreMap;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Properties;
  
  /**
   * This class takes a parameter (review) through the main args and runs it through the sentiment analysis.
   * Where necessary, the analysis breaks the review into shorter sentences and scores each one.
   * If devMode is set to TRUE, the detailed output is displayed in the console.
   * The average of the review sentiments are then returned as a type double.
   */
  public class SentimentAnalysis {
  
      private static ArrayList findSentiment(ArrayList&lt;String[]&gt; allReviews) {
          // Set to TRUE to display the breakdown of the output to the console
          boolean devMode = false;
  
          ArrayList&lt;List&gt; scoredReviewsArray = new ArrayList&lt;&gt;();
          double totalSentimentScore = 0;
          int counter = 1;
  
          // Setup Stanford Core NLP package
          Properties props = new Properties();
          props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
          StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
  
          if (devMode) {
              System.out.println("" +
                      "\n==============================================================================================================\n" +
                      "The output shows the sentiment analysis for the comment provided.\n" +
                      "The StanfordCoreNlp algorithm breaks apart the input and rates each section numerically as follows:\n" +
                      "\n" +
                      "\t1 = Negative\n" +
                      "\t2 = Neutral\n" +
                      "\t3 = Positive\n" +
                      "\n" +
                      "The returned value is the average of all the sentiment ratings for the provided comment.\n" +
                      "==============================================================================================================\n"
              );
          }
  
          for (String[] singleReview : allReviews) {
              ArrayList&lt;String&gt; review = new ArrayList&lt;&gt;();
              String reviewId = singleReview[0];
              review.add(reviewId);
  
              double sentimentSectionScore;
  
              String reviewText = singleReview[1];
  
              if (reviewText != null &amp;&amp; reviewText.length() &gt; 0) {
  
                  Annotation annotation = pipeline.process(reviewText);
  
                  for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
                      Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
  
                      sentimentSectionScore = RNNCoreAnnotations.getPredictedClass(tree);
  
                      totalSentimentScore += sentimentSectionScore;
  
                      if (devMode) {
                          System.out.println("\nSentence " + counter++ + ": " + sentence);
                          System.out.println("Sentiment score: " + sentimentSectionScore);
                          System.out.println("Total sentiment score: " + totalSentimentScore);
                      }
  
                      review.add(sentence.toString());
                      review.add(String.valueOf(sentimentSectionScore));
                  }
  
                  scoredReviewsArray.add(review);
              }
          }
  
          System.out.println(scoredReviewsArray.toString());
  
          return scoredReviewsArray;
      }
  
      public static void main(String[] args) {
  
          // Test array of review arrays
          String mockReview1[] = {"1", "String 1.1. String 1.2.", ""};
          String mockReview2[] = {"2", "String 2", ""};
          String mockReview3[] = {"3", "String 3", ""};
          ArrayList&lt;String[]&gt; reviews = new ArrayList&lt;&gt;();
          reviews.add(mockReview1);
          reviews.add(mockReview2);
          reviews.add(mockReview3);
  
          findSentiment(reviews);
  
      }
  }
  </code></pre>
  
  <p>...and I'm wrapping up my Java application into a Jar to pass in and retrieve the data from ReactJS using a child process, as follows:</p>
  
  <pre><code>const exec = require('child_process').spawn('java', ['-jar', './StanfordNlp.jar', allReviews]);
  
      exec.stdout.on('data', function (data) {
          // Do stuff...
      });
  </code></pre>
  
  <p>Hope this all makes sense, if you need me to clarify anything, please just ask.</p>
  
  <p>Your help is greatly appreciated.</p>
  
  <p>Thanks!</p>