title: String and List manipulation in Java
body: <p>So I want to make function to which I will pass a string say "sandals" and a list with indexes of the string say, [0, 1, 2], this functions needs to return a list which is [6,4,-1] because at index=0, there's "s", it'll traverse the whole string and and find out one more "s" is in 6th position, one more "a" is in 4th position and "n" doesn't occur again, so -1.</p>
  
  <pre><code> import java.util.*;
    class list 
     {
       public void stringnList(String s, list l)
        {
                char arr[]=s.toCharArray();
                Arrays.sort(arr);
                List&lt;int&gt; q = new ArrayList&lt;int&gt;();
                for (int i:l)
                {
                 for(int j=i+1;j&lt;arr.length;j++)
                  {
                    if(arr[i]==arr[j])
                    q.append(j);
                    else
                    q.append(-1);
                 }
          }
      for(int j:q)
      System.out.print(j+"\n");
     }
  }
  </code></pre>
  
  <p>I know my code has errors, but I am having a hard time understanding and fixing them. </p>