How to determine if a String has non-alphanumeric characters?

Tags: , , ,

I need a method that can tell me if a String has non alphanumeric characters. For example if the String is “abcdef?” or “abcdefĂ ”, the method must return true.


HashMap: One Key, multiple Values

How I can get the third value for the first key in this map? Is this possible?


How to convert year month day to proper UTC milliseconds from the epoch?

I am trying to convert a date into milliseconds with the following code: GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone(“UTC”)); gc.clear(); gc.set(1900, 1, 1); …

Tags: enums java

How to convert enum value to int?

Tags: ,

I have a function which return a type int. However, I only have a value of the TAX enumeration. How can I cast the TAX enumeration value to an int? public enum TAX { NOTAX(0),SALESTAX(10),…


Split using a bracket

How can I split a string using [ as the delimiter? String line = “blah, blah [ tweet, tweet”; if I do line.split(“[“); I get an error Exception in thread “main” java.util.regex….


Using Mockito with multiple calls to the same method with the same arguments

Is there a way to have a stubbed method return different objects on subsequent invocations? I’d like to do this to test nondeterminate responses from an ExecutorCompletionService. i.e. to test that …

Android Get Current timestamp?

Tags: , , , ,

I want to get the current timestamp like that : 1320917972 int time = (int) (System.currentTimeMillis()); Timestamp tsTemp = new Timestamp(time); String ts = tsTemp.toString();


Annotation SOURCE Retention Policy

From the Java doc: CLASS: Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. RUNTIME: Annotations are to be recorded in the …

Tags: exception java

No Such Element Exception?

Tags: ,

So here is my code: public static void getArmor(String treasure) throws FileNotFoundException{ Random rand=new Random(); Scanner file=new Scanner(new File (“armor.txt”)); while(!file….

Tags: break java

How to break out or exit a method in Java?

Tags: ,

The keyword break in Java can be used for breaking out of a loop or switch statement. Is there anything which can be used to break from a method?