What you can probably do to parse your string later would be add a custom delimiter at the end of every sub-string as and when you type it as an input. Something like this:
Scanner scan = new Scanner(System.in);
int numOfLines = scan.nextInt(); // Give the number of substrings that you are going to give
String S = "";
while(numOfLines>0)
{
S = scan.next()+"|"; // '|' is your custom delimiter (That symbol is LOGICAL OR symbol.
numOfLines--;
}
This will make sure that a sub-string lies between two '|'s. Later you can use the split() function for splitting the entire string using the custom delimiter.
String[] listString = S.split("|");
This creates an array of sub-strings which were found in between the 2 '|'s. The total number of such sub-strings formed can be found using the .length function
int n = listString.length;
For checking whether the sub-string is an URL, you can download the Apache Commons Validator. Just download the latest version, add it to your java build path. Then create a UrlValidator to validate each individual string.
UrlValidator url = new UrlValidator();
ArrayList<String> al = new ArrayList<String>();
while(n>0)
{
String temp = listString[n-1];
if(url.isValid(temp))
{
al.add(temp);
}
n--;
}
for(String print : al) //For-Each loop
{
System.out.println(print);
}
Hope this helps. :)