Skip to content

Tag: java

Sort ArrayList of strings by length

I want to order an ArrayList of strings by length, but not just in numeric order. Say for example, the list contains these words: They need to be ordered by their difference in length to a special string, for example: So the final list would look like this (difference in brackets): Answer Use a custom compara…

How to grab all words that start with capital letters?

I want to create a Java regular expression to grab all words that start with a capital letter then capital or small letters, but those letters may contain accents. Examples : Where Àdónde Rápido Àste Can you please help me with that ? Answer Regex: Java string: Explanation: Caveat: This only works correctly i…

ant build.xml file doesn’t exist

After the installation of my ant in my windows 7 . In cmd i typed ant -v it’s given the ant version but it says the following also. What’s the problem in the system. How i can rectify this issue? Answer You should use ant -version command instead. The -v option is equivalent of -verbose option. Se…

How to convert comma-separated String to List?

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for that? Answer Convert comma separated String to List The above code splits the string on a delimiter defined as: zero or more whitespace, a…

Sending Java POST request without calling getInputStream()

I would like to send a POST request in Java. At the moment, I do it like this: I do not understand why I have to call con.getInputStream() in order to actually send the request. If I do not call it, the request is not sent. Is there a problem using PrintStream? It should not matter if I take a

Cannot find class even when jar file is in working directory

I am struggling to get my Java program to run on AIX. I used Eclipse on Windows to create a runnable Jar file, jRams.jar below. I kept on getting a class not found error, until finally I put all the external libraries in the same directory. Still, I get the class not found error. jremote.jar definitely contai…