Sorry, I'm totally new to Java. I'm trying to count the same URLs present in objects and I'm not able to figure out how to count them.
I was reading this article https://www.geeksforgeeks.org/passing-and-returning-objects-in-java/ and wondered if this is a way to count URLs object or another way. I'm stuck here for two days.
Can anyone please guide me?
class Main() {
private HashMap<String, String> keyMap;
private static int count = 0;
public String newUrl(String url) {
//Completed: if the url is present in HashMap then return shortUrl else add it and return shortUrl
return shortUrl
}
public Integer countURL(String url){
//int count = Collections.frequency(keyMap.values(), url);
return count;
}
public static void main(String args[]) {
Main a = new Main();
String url = a.newUrl("http://example.com");
String url1 = a.newUrl("http://example2.com");
String url2 = a.newUrl("http://example2.com");
System.out.println(url);
System.out.println(url1);
System.out.println(url2);;
System.out.println(a.countURL("http://example2.com")); //2 if not then 0
}
}