In Java, what would the fastest way to iterate over all the chars in a String, this: Or this: EDIT : What I’d like to know is if the cost of repeatedly calling the charAt method during a long iteration ends up being either less than or greater than the cost of performing a single call to toCharArray at …
Tag: java
How to find ~/.android/debug.keystore in Mac OS X for Android?
I am very new to Android development. Now am facing this problem in Java Eclipse, Error generating final archive: Debug Certificate expired on 1/11/12 12:52 PM Unknown Android Packaging Problem …
Knight’s tour depth-first search infinite loop
I’m trying to solve the knight’s tour problem using a depth-first search algorithm. The algorithm seems te be looping whenever it has two choices that both result in a dead end. I understand that this is caused because the algorithm resets the ‘wasVisited’ boolean to false again whenev…
How to handle a NumberFormatException with Gson in deserialization a JSON response
I’m reading a JSON response with Gson, which returns somtimes a NumberFormatException because an expected int value is set to an empty string. Now I’m wondering what’s the best way to handle this kind of exception. If the value is an empty string, the deserialization should be 0. Expected JS…
How to scan QRCode in android
I found a tutorial on how to scan a barcode. But in my application I have to scan a QR code. How can I a scan QR code in Android? Answer and in onActivityResult():
How to kill currently running task in android
I am trying to build a task killer type of app in android. I can show the list of currently running task using ActivityManager but facing problem in killing the task. Here is what i am doing to get the list of currently running task : It worked for me But now as I am trying to kill the task
Printing the enum’s name
I’m using eclipse + Android SDK on Ubuntu. I would like to print the name of a sensor type device, there a a lot of them and I want to do it automatically. If I use a I print the (int) type, but I would like the name of the enum. How could I do that? Answer For enumerations, you
Testing Private method using mockito
How to test private method is called or not, and how to test private method using mockito? Answer You can’t do that with Mockito but you can use Powermock to extend Mockito and mock private methods. Powermock supports Mockito. Here’s an example.
Using Java NIO with Unix Domain sockets in non-blocking mode with selectors
Is there a way to use Unix Domain sockets with Java NIO? I want to use NIO so that I can use Selectors on it in a single thread. I had a look at junixsocket but it only seems to support normal Sockets not NIO channels that support selectors. Answer You can use the project jnr-unixsocket,(https://github.com/jn…
Fastest way to concatenate multiple strings
I’m working on a function that requires to concatenate multiple strings. Something like 200 – 500 strings. I’m currently using StringBuffer. I wanted to know if this is the fastest way to concatenate multiple strings. I need this method to be as efficient as possible. Answer The StringBuffer…