On a scale of 1 to 10, this is reaching number 10 of frustration, The test urls work, I even added a check that if you enter a non url it still prints it out. thanks for the help.
package com.codegym.task.task15.task1527;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Request parser
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String URL = reader.readLine();
// String URL = "http://codegym.cc/alpha/index.html?obj=3.14&name=Amigo";
// String URL = "http://codegym.cc/alpha/index.html?lvl=15&view&name=Amigo";
String[] myStrArray = URL.split("");
if (URL.contains("&")) {
myStrArray = URL.split("[?]");
myStrArray = myStrArray[1].split("&");
} else {
System.out.println(URL);
System.exit(0);
}
ArrayList<String> pList = new ArrayList<>();
for (String line : myStrArray) {
if (line.contains("="))
pList.add(line.substring(0, line.indexOf('=')));
if (!line.contains("http://") && !line.contains("="))
pList.add(line);
}
for (String param : pList)
System.out.print(param + " ");
System.out.println();
String[] myStrArray2 = null;
for (String line : myStrArray) {
myStrArray2 = (line.split("[=]"));
for (String line2 : myStrArray2) {
if ((line2.contains(".")) &&
(!line2.contains("http"))) {
try {
double d = Double.parseDouble(line2.substring(line2.indexOf('=') + 1));
alert(d);
break;
} catch (Exception e) {
String str = line2.substring(line2.indexOf('=') + 1);
alert(str);
break;
}
}
}
}
}
public static void alert(double value) {
System.out.println("double: " + value);
}
public static void alert(String value) {
System.out.println("String: " + value);
}
}