title: java String to an object
body: <p>I want to convert a <code>String</code> to an object. I looked for related topics but could not find an answer. My code is:</p>
  
  <pre><code>amountShip = 5;
  String name = ReadConsole.nextString(); //--&gt;variabe of the object "Player"
  gamers[i] = Player.String2Object(name, 0);
  
  Player String2Object(String name, int amountShip) {
     Object o = name;
     Player temp = (Player)o;
     temp = new Player(name, amountShip);
     return temp;             
  }
  
  class Player {
      Player (String name, int amountShip) {
          name = name;
          ships = amountShip;
      }
      Player pl = new Player(String name, int amountShip);
  }
  </code></pre>
  
  <p>it says </p>
  
  <blockquote>
    <p>java.lang.String cannot be cast to Gameobjects.Player</p>
  </blockquote>
  
  <p>My intention is to create 2 Player-objects with different instance names dynamically. If for example somebody types in "3", i want to create</p>
  
  <pre><code>Player p1 = new Player(x,y);
  Player p2 = new Player(x,y);
  Player p3 = new Player(x,y);
  </code></pre>
  
  <p>Thanks a lot in advance</p>