fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.net.URI;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. // your code goes here
  14. var uri = new URI("https://123/v1/a/b/");
  15.  
  16. String authority = uri.getAuthority(); // returns 123
  17. System.out.println(authority);
  18.  
  19. String path = uri.getPath(); // returns /v1/a/b/
  20. String pathTrimmed = path.replaceAll("^/", "").replaceAll("/$", ""); // trim leading and trailing slashes: v1/a/b
  21. String[] segments = pathTrimmed.split("/");
  22.  
  23. if (segments.length < 1) return;
  24. System.out.println(segments[0].replaceAll("^v", "")); // version truncated to number: 1
  25. for (int i=1; i < segments.length; i++) {
  26. System.out.println(segments[i]); // remaining segments: a, b, ..
  27. }
  28.  
  29.  
  30. }
  31. }
Success #stdin #stdout 0.1s 55712KB
stdin
Standard input is empty
stdout
123
1
a
b