Tags:

Growing ByteBuffer


Has anyone has ever seen an implementation of java.nio.ByteBuffer that will grow dynamically if a putX() call overruns the capacity? The reason I want to do it this way is twofold: I don’t know how …

Tags:

How can I write a byte array to a file in Java?


How to write a byte array to a file in Java?

Tags:

Java: splitting a comma-separated string but ignoring commas in quotes


I have a string vaguely like this: foo,bar,c;qual=”baz,blurb”,d;junk=”quux,syzygy” that I want to split by commas — but I need to ignore commas in quotes. How can I do this? …

Show padding zeros using DecimalFormat

Tags: , ,


I’m using DecimalFormat to format doubles to 2 decimal places like this: DecimalFormat dec = new DecimalFormat(“#.##”); double rawPercent = ( (double)(count.getCount().intValue()) / …

Iteratively compute the Cartesian product of an arbitrary number of sets

Tags: , , , ,


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 Array Sort descending?

Tags: , , ,


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 :[

Tags:

Converting JSON data to Java object


I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string …

Tags:

How should equals and hashcode be implemented when using JPA and Hibernate


How should model class’s equals and hashcode be implemented in Hibernate? What are the common pitfalls? Is the default implementation good enough for most cases? Is there any sense to use business …

Tags:

“Cannot get the revision information from the scm repository”


I get maven error : Cannot get the revision information from the scm repository Any idea how to solve this?

Tags:

How to obtain all subsequence combinations of a String (in Java, or C++ etc)


Let’s say I’ve a string “12345” I should obtain all subsequence combinations of this string such as: –> 1 2 3 4 5 –> 12 13 14 15 23 24 25 34 35 45 –> 123 124 125 234 235 345 –> 1234 1235 1245 …