Title asks it all… I want to do a multi field – phrase search in Lucene.. How to do it ? for example : I have fields as String s[] = {“title”,”author”,”content”}; I want to search harry potter across all fields.. How do I do it ? Can someone please provide an ex…
Tag: java
Java switch statement multiple cases
Just trying to figure out how to use many multiple cases for a Java switch statement. Here’s an example of what I’m trying to do: versus having to do: Any ideas if this possible, or what a good alternative is? Answer Sadly, it’s not possible in Java. You’ll have to resort to using if-e…
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…
javac error: Class names are only accepted if annotation processing is explicitly requested
I get this error when I compile my java program: Here is the java code (I’m running this on Ubuntu). Here is the javac command: How do I compile this program? Answer You at least need to add the .java extension to the file name in this line: From the official faq: Class names, ‘HelloWorldApp’…
How to change the decimal separator of DecimalFormat from comma to dot/point?
I have this little crazy method that converts BigDecimal values into nice and readable Strings. It however, also produces a so called grouping separator “,” that makes all my values come out like this: I do need the separator to be a dot or a point and not a comma. Does anybody have a clue of how …
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…