Skip to content

Java: convert List to a join()d String

JavaScript has Array.join() Does Java have anything like this? I know I can cobble something up myself with StringBuilder: .. but there’s no point in doing this if something like it is already part of the JDK. Answer String.join With Java 8 you can do this without any third party library. If you want to…

EXT GWT + java EE

My question is: what is the best way to send my Java EE annotated entity beans’ data to the clientside to use it in a grid for example? Surely I could make the BaseModel-extended client models for each entity manually, but I wonder what could be the best-practice here. I need a step-by-step tutorial if …

How to get full REST request body using Jersey?

How can one get the full HTTP REST request body for a POST request using Jersey? In our case the data will be XML. Size would vary from 1K to 1MB. The docs seem to indicate you should use MessageBodyReader but I can’t see any examples. Answer Turns out you don’t have to do much at all. See below &…

Java: Literal percent sign in printf statement

I’m trying to add an actual percent sign into a printf statement in Java and I’m getting the error: I can’t figure out how to put an actual percent sign into my printf? I thought using % to escape it would work, but it isn’t. Any ideas? Answer The percent sign is escaped using a percen…

Simple way to get wrapper class type in Java

I have a piece of code where I need to pass the class of a field in a method. Because of the mechanics of my code I can only handle reference objects and not primitives. I want an easy way of determining if a Field’s type is primitive and swap it with the appropriate wrapper class. So in code what

Java Array Sort descending?

Is there any EASY way to sort an array in descending order like how they have a sort in ascending order in the Arrays class? Or do I have to stop being lazy and do this myself :[ Answer You could use this to sort all kind of Objects Arrays.sort() cannot be used directly to sort primitive arrays in descending