title: Return different type of data from a method in java?
body: <pre><code>public static void main(String args[]) {
      myMethod(); // i am calling static method from main()
   }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>public static ? myMethod(){ // ? = what should be the return type
      return value;// is String
      return index;// is int
  }
  </code></pre>
  
  <p><code>myMethod()</code> will return String and int value. So take these returning values from <code>main()</code> i came up with following solution. </p>
  
  <p>create a class call <code>ReturningValues</code></p>
  
  <pre><code>public class ReturningValues {
  private String value;
  private int index;
  
  // getters and setters here
  }
  </code></pre>
  
  <p>and change <code>myMethod()</code> as follows. </p>
  
  <pre><code> public static ReturningValues myMethod() {
      ReturningValues rv = new ReturningValues();
      rv.setValue("value");
      rv.setIndex(12);
      return rv;
  }
  </code></pre>
  
  <p>Now my question,is there any easier way to achieve this??  </p>