Skip to content

Most efficient way to cast List to List

I have a List<SubClass> that I want to treat as a List<BaseClass>. It seems like it shouldn’t be a problem since casting a SubClass to a BaseClass is a snap, but my compiler complains that the cast is impossible. So, what’s the best way to get a reference to the same objects as a List&…

bring JInternalFrame to the front

I have a JDesktopPane which contains a number of JInternalFrames. I’d like to be able to bring any JInternalFrame to the front, overlaying any other active frames. I found a number of code samples to do this, but none seem to work – the frame does NOT go on top of other active JInternalFrames. E.g…

Finding Java Enum types from code values?

We use code values in our database, and Enums in Java. When querying the database, we need to take a code value and get an Enum instance. Is it overkill to have a HashMap to avoid iteration? What would you do? Is there an easier way? Answer That’s exactly the approach I’d take to solve that partic…

Applet: Java heap space

Due to a small implementation mistake I discovered how quickly I could reach a Java heap space issue now the bug is fixed everything is fine but it did get me looking into how to solve this and I foudn multiple solution such as java -Xms5m -Xmx15m MyApp the problem is that this changes the java memory on my c…

Regular expression with variable number of groups?

Is it possible to create a regular expression with a variable number of groups? After running this for instance… … I would like to have something like m.group(1) = “c” m.group(2) = “d” m.group(3) = “d” m.group(4) = “c”. (Background: I’m parsing…

How to get the decimal part of a float?

I need to extract the decimal part of a float number, but I get weird results: Why does this happen? Why do I get those values instead of 0.65? Answer float only has a few digit of precision so you should expect to see a round error fairly easily. try double this has more accuracy but still has rounding error…

Default properties of Java Annotation

What are the exact default values of two meta annotations (Target and Retention) in a user defined annotation? Answer According to the source code, none of them has a default value, which means you must provide it, whenever you use the annotation. The meaning of the missing annotation is defined in the javado…