Recent Notes

Displaying keyword search results 101 - 110
Created by alfa on May 27, 2011 11:19:29    Last update: May 31, 2011 07:56:26
This is a utility to convert a string value to one of the primitive type values. It is useful in Java reflection code where the value comes in as a string (e.g., from XML parsing), and the type of the value cannot be decided until runtime. import java.util.*; import java.lang.reflect.*;... Note: This method can be extended to convert string to more complex types by writing a converter for the destination type. For example, to convert string to date: public class DateConverter { public static ... Usage: Date d = (Date) ConvertUtil.convert("10/12/2010", ...
Created by alfa on May 27, 2011 15:46:44    Last update: May 27, 2011 15:46:44
Example code: import java.lang.reflect.*; public class Co...
Created by alfa on May 26, 2011 20:20:50    Last update: May 26, 2011 20:20:50
You would never have guessed it. The test is: Modifier.isStatic(method.getModifiers()) ! Example code: import java.lang.reflect.Method; import java.la...
Created by alfa on May 24, 2011 14:52:53    Last update: May 26, 2011 19:52:12
import java.lang.reflect.Method; public cla...
Created by alfa on May 25, 2011 21:17:18    Last update: May 25, 2011 21:18:04
The Java regex expression \B matches a non-word boundary, which is anything other than a word boundary. import java.util.regex.*; public class NonW... Output: p1 match: word at 40 p1 match: word at 83 ...
Created by alfa on May 25, 2011 20:56:16    Last update: May 25, 2011 20:57:31
The general construct of a non-capturing group is: (?:X) , i.e., add ?: after the opening bracket of an otherwise capturing group. Example code: import java.util.regex.*; public class NonC... Output: Matched: a capturing Subgroup 1: a Subgroup ...
Created by alfa on May 25, 2011 20:17:52    Last update: May 25, 2011 20:39:35
In Java regex, by default, the dot character does not match the newline character ( \n ). It matches a newline character only when the DOTALL flag is set. Example: import java.util.regex.*; public class Dota...
Created by alfa on May 25, 2011 20:08:21    Last update: May 25, 2011 20:08:21
In MULTILINE mode, ^ matches the begging of the string as well as the beginning of a new line; $ matches the end-of-string as well as the newline character. In normal (non- MULTILINE mode), ^ only matches the begging of the string; $ only matches the end-of-string. Example: import java.util.regex.*; public class ...
Created by alfa on May 25, 2011 15:22:08    Last update: May 25, 2011 15:25:05
Use Matcher.find() to find the next regex match until all matches are exhausted. import java.util.regex.*; public class RegE... To get case insensitive match, use: Pattern p = Pattern.compile("(?i)\\b(m|c)\\w*(n|r|...
Created by alfa on May 24, 2011 15:59:41    Last update: May 24, 2011 15:59:41
Java reflection with Apache beanutils example. import org.apache.commons.beanutils.MethodUtils; ...
Previous  6 7 8 9 10 11 12 13 14 15 Next