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. String string = "Youremail@gmail.comAnotheremail@gmail.comSomeemail@gmail.com";
  13.  
  14. int prevPos = 0, nextPos;
  15. List<String> emailList = new ArrayList<>();
  16. final String SEARCH_STR = "@gmail.com";
  17. final int SEARCH_STR_LENGTH = SEARCH_STR.length();
  18.  
  19. /**** start code *****/
  20. while (true) {
  21. nextPos = string.indexOf(SEARCH_STR, prevPos);
  22. if (nextPos == -1)
  23. break;
  24.  
  25. emailList.add(string.substring(prevPos, nextPos + SEARCH_STR_LENGTH));
  26. prevPos = nextPos + SEARCH_STR_LENGTH;
  27. }
  28. /**** end code *****/
  29.  
  30. for (String test : emailList) {
  31. System.out.println(test);
  32. }
  33.  
  34. }
  35. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
Youremail@gmail.com
Anotheremail@gmail.com
Someemail@gmail.com