I have an interface with a method that expects an array of Foo: I am mocking this interface using Mockito, and I’d like to assert that doStuff() is called, but I don’t want to validate what argument are passed – “don’t care”. How do I write the following code using any(), the generic method, instead of anyObject()? Answer Since Java
Tag: java
Syntax error on token “;”, { expected after this token
why is there syntax error on this line ( shown below ) Answer You forgot the entry point method declaration. Try adding: before the line where you got the error.
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 join a Collection of Strings
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 possible. Answer I’ve been using
Show padding zeros using DecimalFormat
I’m using DecimalFormat to format doubles to 2 decimal places like this: DecimalFormat dec = new DecimalFormat(“#.##”); double rawPercent = ( (double)(count.getCount().intValue()) / …
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 –
Iteratively compute the Cartesian product of an arbitrary number of sets
I want to compute the cartesian product of an arbitrary number of nonempty sets in Java. I’ve wrote that iterative code… public static List<Set> cartesianProduct(List<…
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 percent sign: The complete syntax
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 :[