Archive for the ‘Uncategorized’ Category

h1

Not Being Evil (Google and Japan)

March 11, 2011

This post isn’t about Java, or food or an interesting quote. It’s about Google honoring its corporate motto of Don’t Be Evil. Not only are they not being evil, but they’ve done a good thing today.

Within hours of the recent earthquake in Japan they’ve set up a Google Crisis Response for the 2011 Japanese Earthquake and Tsunami.The page has alerts and warnings, bulletin boards, transportation information, power outages information, maps (with KML data links so it can be used in other applications) and a Person Finder where people can post information about people they are looking for or people they have information about.

That’s awesome! Kudos to the folks at Google!

Feel free to leave comments below.

Josh

Advertisements
h1

Extracting Integers from Strings

October 7, 2008

The following snippet of source code extracts a single digit from a String and converts it to an int. The String.charAt() method takes a zero-based index of the position of the character to be extracted from the String and the Character.digit() method takes the String from which to extract the digit and the radix.

In the example below I pass 0 to the charAt() method since I want the first character extracted and I pass 10 as the radix since I’m working in base 10.


String myString = "3blindmice";
int digit = Character.digit(myString.charAt(0), 10);
System.out.println("Digit: " + digit);

Output: 3

If the position passed to charAt is not a valid position within the String then a java.lang.StringIndexOutOfBoundsException is thrown.

If the radix is not between Character.MIN_RADIX and Character.MAX_RADIX, -1 is returned.

Comments, alternate solutions and related snippets of code are welcome.

Joshua Smith


References:

API for java.lang.Character.digit(char, int)

API for java.lang.String.charAt(int)