-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestMain.java
36 lines (28 loc) · 865 Bytes
/
TestMain.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.tutorials;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
public class TestMain {
public static void main(String[] args)
{
List<String> urls = Arrays.asList("http://www.fancysite.com", "http://www.fancysite.com/xyz/xyz.html", "http://www.fancysite.com/abc/xyz/pqr.html");
TestMain t=new TestMain();
t.countLevelOfUrls(urls);
}
public void countLevelOfUrls(List<String> urls)
{
for (String url : urls) {
try {
URI uri = new URI(url);
String path = uri.getPath();
int length = (path.split("/")).length;
System.out.println(uri +" is at level "+ (length-1));
}
catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}