The following code in Java uses recursion to create all possible substrings from a string. I am wondering is there a better way of coding this? I want to use recursion. FAQ Q – Why do I want to do this using recursion? A – Because the CEO of StackOverflow says recursion is important http://www.joe…
Tag: java
Wildcard pattern for RoutingAppender of Log4j2
I am trying to use the new RoutingAppender of Log4j2 to route the different logs based on the MDC (ThreadContext in Log4j2). What I want to do is the following: If MDC map has $contextId -> Append to $contextId appender (specific log) If MDC does not have $contextId -> Append to main appender (general l…
Print out elements from an Array with a Comma between the elements
I am printing out elements from an ArrayList and want to have a comma after each word except the last word. Right now, I am doing it like this: It prints out the words like this: The problem is the last comma. How do I solve it? Answer Print the first word on its own if it exists. Then print
Android: Image upload to web-service loses EXIF data
Please help, I currently upload an image to my web-service which does have the EXIF data attached to it at time of upload. When it arrives on the server, it is minus it’s exif data. Before I upload the image, it’s stored to the devices SD card to which is then decoded using the BitmapFactory class…
How to pass an action name using hyperlink in Struts 2?
I have a hyperlink named “Click for new User”. Once I click the link, I got NullPointerException instead of opening RegisterPage.jsp page. I post my code here, I can’t find my mistake index.jsp: struts.xml: Login.java(Action Class): Exception: Answer When you click on hyperlink you don’…
Java collections faster than c++ containers?
I was reading the comments on this answer and I saw this quote. Object instantiation and object-oriented features are blazing fast to use (faster than C++ in many cases) because they’re designed in from the beginning. and Collections are fast. Standard Java beats standard C/C++ in this area, even for mo…
Is it possible to install 64 bit JVM on linux so heap can be larger then 2gb?
It’s a 32 bit Ubuntu OS I want to be able to run with more than 2g of heap Answer No. A 32-bit kernel(and likely 32-bit CPU as well) cannot run a 64-bit executable for the JVM(or any other 64-bit executable/ELF) with your choice of OS and kernel.
How do I get the `.class` attribute from a generic type parameter?
The accepted answer to this question describes how to create an instance of T in the Generic<T> class. This involves passing in a Class<T> parameter to the Generic constructor and callin the newInstance method from that. A new instance of Generic<Bar> is then created, and the parameter Bar.c…
Read directory inside JAR with InputStreamReader
So, this question has been asked a million times i believed and I’ve been reading them for a couple of hours and trying several options given by some people but none of them work for me. I want to list all the files inside a directory inside the application’s JAR, so in IDE this works: That gives …
Make immutable Java object
My goal is to make a Java object immutable. I have a class Student. I coded it in the following way to achieve immutability: My question is, what is the best way to achieve immutability for the Student class? Answer Your class is not immutable strictly speaking, it is only effectively immutable. To make it im…