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. // your code goes here
  13. String str = "This is a test\nAnother test\n#art\n#paintings#collections";
  14.  
  15. System.out.println(str + "\n--------------------");
  16. String tag_name ="";
  17. String[] sp = str.split(" |\n");
  18. for (int j =0; j<sp.length; j++) {
  19. //System.out.println(""+sp[j]);
  20. if ( String.valueOf(sp[j].charAt(0)).equals("#")) {
  21. tag_name = sp[j];
  22. String[] np = tag_name.split("#");
  23. for (int k = 0; k<np.length; k++) {
  24. if(np[k].length() >0 ) {
  25. tag_name = np[k].replaceAll("\n", "");
  26. System.out.println(""+ np[k]);
  27. }
  28. }
  29. //System.out.println("" + tag_name);
  30. }
  31. }
  32.  
  33. }
  34. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
This is a test
Another test
#art
#paintings#collections
--------------------
art
paintings
collections