The title pretty much says it all. What’s the simplest/most elegant way that I can convert, in Java, a string from the format “THIS_IS_AN_EXAMPLE_STRING” to the format “ThisIsAnExampleString”? I figure there must be at least one way to do it using String.replaceAll() and a regex.…
How to escape a square bracket for Pattern compilation?
I have comma separated list of regular expressions: I have done a split on the comma. Now I’m trying to match this regex against a generated password. The problem is that Pattern.compile does not like square brackets that is not escaped. Can some please give me a simple function that takes a string like…
How to rotate text in a spreadsheet cell using Apache POI?
How can I rotate the text within an HSSFCell class of Apache POI? Answer Use HSSFCellStyle, that class has a method called setRotation(short rotation) which will rotate the text. All you do is apply the cell style to a cell:
Making a JPanel manually resizable
I have a JFrame with BorderLayout as the layout manager. In the south border, I have a JPanel, I want this JPanel’s size to be adjustable by the user, i.e. the user can click on the edge of the border and drag it up to make it larger. Is there any way you know that I can do this? Answer
Determine the size of an InputStream
My current situation is: I have to read a file and put the contents into InputStream. Afterwards I need to place the contents of the InputStream into a byte array which requires (as far as I know) the size of the InputStream. Any ideas? As requested, I will show the input stream that I am creating from an upl…
How to display X-Bar statistics symbol in Java Swing label?
What’s the best way to insert statistics symbols in a JLabel’s text? For example, the x-bar? I tried assigning the text field the following with no success: Answer Html codes will not work in Java. However, you can use the unicode escape in Java Strings. For example: Also, here is a cool website f…
A for-loop to iterate over an enum in Java
I have an enum in Java for the cardinal and intermediate directions: How can I write a for loop that iterates through each of these enum values? Answer .values() You can call the values() method on your enum. This values() method is implicitly declared by the compiler. So it is not listed on Enum doc.
How to navigate from one screen to another screen
How to navigate from one Activity screen to another Activity screen? In the first screen I’m having one button if I click the button it has to move to another Activity screen. Answer
Is there a function in Android analogous to “int main” in C/C++ which contains the program’s main loop?
Normally in a C or C++ program there’s a main loop/function, usually int main (). Is there a similar function that I can use in android Java development? Answer As far as an Android program is concerned there is no main(). There is a UI loop that the OS runs that makes calls to methods you define or ove…
Java implementation for Min-Max Heap?
Do you know of a popular library (Apache, Google, etc, collections) which has a reliable Java implementation for a min-max heap, that is a heap which allows to peek its minimum and maximum value in O(1) and to remove an element in O(log n)? Answer From Guava: MinMaxPriorityQueue.