title: Java: Is there any simpler way to parse array elements from string?
body: <p>In the application there is a string in the following format:</p>
  
  <p>String elements = "[11, john,][23, Adam,][88, Angie,]..." (... means there are more elements in the string)</p>
  
  <p>From the given string I have to create an ArrayList for name IDs (11, 23, 88, ...) and ArrayList for names (john, Adam, Angie, ...)</p>
  
  <p>I created two methods: </p>
  
  <pre><code>private int getItemID(int listLocation, String inputString){
      int indexBeginning = inputString.indexOf("[", listLocation) + 1;
      int indexEnd = inputString.indexOf(",", listLocation) - 1;
      String sID = inputString.substring(indexBeginning, indexEnd);
      int result = Integer.parseInt(sID);
      return result;
  }
  
  private String getItemName(int listLocation, String inputString){
      int indexBeginning = inputString.indexOf(" ", listLocation) + 1;
      int indexEnd = inputString.indexOf(",", indexBeginning) - 1;
      String result = inputString.substring(indexBeginning, indexEnd);
      return result;
  }
  </code></pre>
  
  <p>and intend to use these two methods in the method parseArrayString(String inputString), which I haven't written yet but would work the following way:</p>
  
  <pre><code>private void parseCommunityList(String inputString){
          int currentLocation = 0;
          int itemsCount = count the number of "[" characters in the string
          for(int i = 0; i &lt; itemsCount; i++)
          {
                 currentLocation = get the location of the (i)th character "[" in the string;
                 String name = getItemName(currentLocation, inputString);
                 int ID = getItemID(currentLocation, inputString);
                 nameArray.Add(name);
                 idArray,Add(ID);
          }
  
      }
  </code></pre>
  
  <p>I would appreciate if anyone of you could suggest any simpler way to create two ArrayLists from the given string.</p>
  
  <p>Thanks!</p>