Skip to content

Tag: java

Converting a Map into a sorted TreeSet using streams

The code is: Where the HashMap is There are 2 problems I run into using this code. First, for some reason Map.Entry::getValue runs into the error : The target type of this expression must be a functional interface I think the problem here is that the comparator cannot compare between two objects of type Vehic…

My reverse a string code includes a space at the end of the string

I am a beginner of Java, and would like to reverse the character order of a sentence when I input some words as command line arguments. Here is my code. When I input “This is a pen.”, the output should be “.nep a si sihT”. However, the output of this code is “.nep a si sihT &#822…

How to remove everything from ListView using a button onClick?

How to remove everything from ListView using a button onClick? When i try “fullCourseList.clear();”, I can’t add any more courses and the page is refreshed only after visiting the page again Answer You should save off the adapter so you can call clear() on it. Clearing the list this way will…

Setting connection properties on the URL object

Question: Is there a way to set the connection properties on the URL object? Background: We are connecting to a remote server that requires certain connection properties to be set (e.g. User-Agent but certain proprietary properties as well). We are currently using the setRequestProperty method on the URLConne…