fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. ArrayList<String> packageName = new ArrayList<String>();
  13. packageName.add("com.example.dummy");
  14. packageName.add("edu.app.reading");
  15. ArrayList<Integer> index = getIndex(packageName);
  16.  
  17. for (int i = 0; i < index.size(); i ++) {
  18. System.out.println(index.get(i));
  19. }
  20. }
  21.  
  22. private static ArrayList<Integer> getIndex(ArrayList<String> searchName) {
  23. ArrayList<Integer> indexList = new ArrayList<Integer>();
  24. String[] collectionData = new String[] { "com.example.app",
  25. "com.example.appdemo", "com.example.dummy", "edu.app.reading",
  26. "edu.app.knowledge" };
  27.  
  28. /*
  29.   * for iterating each and every item of list
  30.   */
  31. for (int i = 0; i < searchName.size(); i++) {
  32. //Log.i("MISSION", "value will be: " + searchName.get(i).toString());
  33. /*
  34. * for searching listItem in package name array
  35. */
  36. indexList.add(Arrays.asList(collectionData).indexOf(searchName.get(i)));
  37. /*for (int j = 0; j < collectionData.length; j++) {
  38. indexList.add(Arrays.toList().indexOf(searchName.get(i).toString()));
  39. break;
  40. }*/
  41. }
  42. return indexList;
  43. }
  44. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
2
3