Last week was quite tough for me dealing with the project I was working on. The project was quite simple actually. It was released on App Store and the client decided to make minor changes to the application. I made the requested changes and the application was resubmitted to the App Store. Then we got Apple's email saying that the app was rejected. The email said:
"We found that your app does not follow the iOS Data Storage Guidelines https://developer.apple.com/icloud/documentation/data-storage/, which is not in compliance with the App Store Review Guidelines https://developer.apple.com/appstore/resources/approval/guidelines.html#functionality.
In particular, we found that the app is storing too much data, which can be recreated, in the incorrect location."
I have to admit that I don't visit Apple Developer Portal regularly to check if there are any update on their Developer Guidelines. So the thing is our data was stored in document folder and I need to move application's data to library/cache folder for prior iOS 5.0.1 and setting "do not back up" attribute for iOS 5.0.1 above. Thanks to iCloud, iSun, iMoon and whatever it is on the sky above.
There was another thing screwed me, the core data. Core data needs versioning if you happen to change the data structure like adding columns, changing relationships, renaming tables, etc. Apple has documentation about it but don't expect everything goes smoothly as there are many things undocumented. If you find any errors, stackoverflow.com is your help.
Last thing is, I think it is always a good idea to introduce a User Default value that holds your application version early when you start developing your app. It is useful if you need to trace what application version installed on a device. Usually you need this when there are any update for your app.
Friday, February 10, 2012
Sunday, December 18, 2011
SWT JFace
Finally finished writing SWT simple application. The PDF and source code compressed in rar are provided below:
Friday, December 16, 2011
Subversion
I had problem with XCode 4.2 source control recently. It just keeps saying "Host unreachable". It worked perfect in XCode 3.2.5. Spending some time just to figure out what happened was completely waste of time as the Subversion Server host is 100% reachable. So I decided to download separate subversion client for mac. There are some subversion clients out there for mac but finally I choose RapidSVN and SmartSVN. Both are good and has friendly user interface.
RapidSVN can be found here. For the server I prefer VisualSVN for windows. For subversion client at windows the one and only TortoiseSVN is still unbeatable.
RapidSVN can be found here. For the server I prefer VisualSVN for windows. For subversion client at windows the one and only TortoiseSVN is still unbeatable.
Tuesday, November 8, 2011
GWT 2
Finally finished writing GWT simple application. There are four docs here.
1. GWT Getting Started shows you how to create a GWT app in Eclipse.
2. GWT Client Example shows you how to create client side code in GWT.
3. GWT Server Example shows you how to create server side code in GWT.
4. GWT Advance Example shows you how to integrate GWT and some other Google libs.
1. GWT Getting Started shows you how to create a GWT app in Eclipse.
2. GWT Client Example shows you how to create client side code in GWT.
3. GWT Server Example shows you how to create server side code in GWT.
4. GWT Advance Example shows you how to integrate GWT and some other Google libs.
Tuesday, October 18, 2011
Generic
Generic can be placed in class/interface declaration, variable declaration, method parameter or method return value.
In method return value :
public static <B> List<B> aMethod() {...} // any reference can replace B.
In method parameter :
public static <B> List<B> aMethod(B b) {...} // any reference can replace B.
public <B> void aMethod(B b) {...} // any reference can replace B
public <B extends Number> void aMethod(B b) {...} // B must be subclass of Number
In variable declaration :
List<String> list = new ArrayList<String>(); // list of String, no other type
In interface or class declaration :
interface IDao <X extends IEntity> {...} // X must be subclass of IEntity
interface IBidDao extends IDao<Bid> // Bid replaces X and Bid is subclass of IEntity
class BaseDao<X extends IEntity> implements IDao<X> // BaseDao takes X which is then substitutes X in IDao
We can put ? to replace B or X above, which also means any but with restrictions:
List<?> list = new ArrayList<Integer>(); means any class can fit in, and as for List, we can't add object to the list. In general, all of the methods in List that take the generic object as parameter are not applicable (compile error as in add, addAll, etc).
List<? extends Number> list = new ArrayList<Integer>(); means any class that extends Number can fit in, and as for List, we can't add object to the list. In general, all of the methods in List that take the generic object as parameter are not applicable (compile error as in add, addAll, etc).
List<? super Number> list = new ArrayList<Object>(); means any class on top of Number inheritance hierarchy can fit in, and as for List, we can add object to the list as opposed to <?> or <? extends Number>.
The ? and super keyword in generic only apply to variable declaration or method parameter not to class declaration:
List<? extends Number> list = new ArrayList<Integer>();
public void aMethod(List<? extends Number> list) {...}
In method return value :
public static <B> List<B> aMethod() {...} // any reference can replace B.
In method parameter :
public static <B> List<B> aMethod(B b) {...} // any reference can replace B.
public <B> void aMethod(B b) {...} // any reference can replace B
public <B extends Number> void aMethod(B b) {...} // B must be subclass of Number
In variable declaration :
List<String> list = new ArrayList<String>(); // list of String, no other type
In interface or class declaration :
interface IDao <X extends IEntity> {...} // X must be subclass of IEntity
interface IBidDao extends IDao<Bid> // Bid replaces X and Bid is subclass of IEntity
class BaseDao<X extends IEntity> implements IDao<X> // BaseDao takes X which is then substitutes X in IDao
We can put ? to replace B or X above, which also means any but with restrictions:
List<?> list = new ArrayList<Integer>(); means any class can fit in, and as for List, we can't add object to the list. In general, all of the methods in List that take the generic object as parameter are not applicable (compile error as in add, addAll, etc).
List<? extends Number> list = new ArrayList<Integer>(); means any class that extends Number can fit in, and as for List, we can't add object to the list. In general, all of the methods in List that take the generic object as parameter are not applicable (compile error as in add, addAll, etc).
List<? super Number> list = new ArrayList<Object>(); means any class on top of Number inheritance hierarchy can fit in, and as for List, we can add object to the list as opposed to <?> or <? extends Number>.
The ? and super keyword in generic only apply to variable declaration or method parameter not to class declaration:
List<? extends Number> list = new ArrayList<Integer>();
public void aMethod(List<? extends Number> list) {...}
Monday, October 10, 2011
Java Collection
List - List of things.
1. ArrayList -> Growable array. Good for fast iteration but not for a lot of insertion and deletion.
2. Vector -> Same as ArrayList but its methods are synchronized for thread safety.
3. LinkedList -> Same as ArrayList. Good for fast insertion and deletion but not for iteration.
Set - Unique things
1. HashSet -> Collection with no duplicate objects and unpredictable iteration order.
2. LinkedHashSet -> Ordered version of HashSet, ordered in which they are inserted.
3. TreeSet -> Sorted Set by natural order using Red-Black tree structure.
Map - Things with unique ID
1. HashMap -> The simplest map class.
2. Hashtable -> Same as HashMap but its methods are synchronized for thread safety.
3. LinkedHashMap -> Ordered version of HashMap, ordered in which they are inserted.
4. TreeMap -> Sorted Map by natural order.
Queue - Things arranged by the order in which they are to be processed
1. PriorityQueue
Comparable & Comparator
When we add two objects in a collection that doesn't allow duplication as in Set, we have to override the Objet.equals() method as well as Object.hashCode() method. But now we want to make all objects in a List or array sortable, that's why we have to deal with two interfaces: Comparable and Comparator.
Comparable
Implements Comparable interface in the bean class to make the bean comparable:
public class SerializableBean implements Comparable {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int compareTo(SerializableBean o) {
return name.compareTo(o.name);
}
}
Now we can sort the list or array containing the beans using:
Collections.sort(list);
Arrays.sort(arr);
We can also find an index of an object inside the collection using binary search tree after sorting it:
Collections.binarySearch(list, key);
Arrays.binarySearch(arr, key);
Comparator
Create a new class that implements Comparator interface:
public class CompareByName implements Comparator {
@Override
public int compare(SerializableBean bean1, SerializableBean bean2) {
return bean1.getName().compareTo(bean2.getName());
}
}
Now we can use it to sort a list or array:
Collections.sort(list, new CompareByName());
Arrays.sort(arr, new CompareByName());
We can also find an index of an object inside the collection using binary search tree after sorting it:
Collections.binarySearch(list, key, new CompareByName());
Arrays.binarySearch(arr, key, new CompareByName());
Comparable
Implements Comparable interface in the bean class to make the bean comparable:
public class SerializableBean implements Comparable
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public int compareTo(SerializableBean o) {
return name.compareTo(o.name);
}
}
Now we can sort the list or array containing the beans using:
Collections.sort(list);
Arrays.sort(arr);
We can also find an index of an object inside the collection using binary search tree after sorting it:
Collections.binarySearch(list, key);
Arrays.binarySearch(arr, key);
Comparator
Create a new class that implements Comparator interface:
public class CompareByName implements Comparator
@Override
public int compare(SerializableBean bean1, SerializableBean bean2) {
return bean1.getName().compareTo(bean2.getName());
}
}
Now we can use it to sort a list or array:
Collections.sort(list, new CompareByName());
Arrays.sort(arr, new CompareByName());
We can also find an index of an object inside the collection using binary search tree after sorting it:
Collections.binarySearch(list, key, new CompareByName());
Arrays.binarySearch(arr, key, new CompareByName());
Thursday, October 6, 2011
SCJP 6 Part IX - Formatting String with Formatter
Here is the format
%[arg_index$][flags][width][.precision]conversion_char
arg_index
An integer followed directly by a $, this indicates which argument should be printed in this position.
flags
"-" Left justify this argument
"+" Include a sign (+ or -) with this argument
"0" Pad this argument with zeroes
"," Use locale-specific grouping separators
"(" Enclose negative numbers in parentheses
width
This value indicates the minimum number of characters to print.
precision
When formatting a floating-point number, precision indicates the number of digits to print after the decimal point.
conversion_char
The type of argument we'll be formatting.
b boolean
c char
d integer
f floating point
s string
Formatter formatter = new Formatter(System.out);
// format int and use italian switzerland separator
formatter.format(new Locale("it", "ch"), "%,d", 1000000); // 1'000'000
// format int, use italian switzerland separator, and give parentheses for negative int
formatter.format(new Locale("it", "ch"), "%(,d", -1000000); // (1'000'000)
// format int, use italian switzerland separator, and put a sign on it
formatter.format(new Locale("it", "ch"), "%,+d", 1000000); // +1'000'000
%[arg_index$][flags][width][.precision]conversion_char
arg_index
An integer followed directly by a $, this indicates which argument should be printed in this position.
flags
"-" Left justify this argument
"+" Include a sign (+ or -) with this argument
"0" Pad this argument with zeroes
"," Use locale-specific grouping separators
"(" Enclose negative numbers in parentheses
width
This value indicates the minimum number of characters to print.
precision
When formatting a floating-point number, precision indicates the number of digits to print after the decimal point.
conversion_char
The type of argument we'll be formatting.
b boolean
c char
d integer
f floating point
s string
Formatter formatter = new Formatter(System.out);
// format int and use italian switzerland separator
formatter.format(new Locale("it", "ch"), "%,d", 1000000); // 1'000'000
// format int, use italian switzerland separator, and give parentheses for negative int
formatter.format(new Locale("it", "ch"), "%(,d", -1000000); // (1'000'000)
// format int, use italian switzerland separator, and put a sign on it
formatter.format(new Locale("it", "ch"), "%,+d", 1000000); // +1'000'000
SCJP 6 Part VIII - Regex With Scanner
// split string by a dot
Scanner scanner = new Scanner("my.name.is.budi");
scanner.useDelimiter("\\.");
while (scanner.hasNext()) {
System.out.println(scanner.next());
}
result:
my
name
is
budi
// split string by regex (zero or one comma) and a space
Scanner scanner1 = new Scanner("1 isn't true, 0 isn't false, 2.0 is double");
scanner1.useDelimiter("[,]? ");
while (scanner1.hasNext()) {
// is the next token can be converted to int
if (scanner1.hasNextInt()) {
System.out.println("Found int : " + scanner1.nextInt());
// is the next token can be converted to boolean
} else if (scanner1.hasNextBoolean()) {
System.out.println("Found boolean : " + scanner1.nextBoolean());
// is the next token can be converted to double
} else if (scanner1.hasNextDouble()) {
System.out.println("Found double : " + scanner1.nextDouble());
} else {
System.out.println(scanner1.next());
}
}
result:
Found int : 1
isn't
Found boolean : true
Found int : 0
isn't
Found boolean : false
Found double : 2.0
is
double
Scanner scanner = new Scanner("my.name.is.budi");
scanner.useDelimiter("\\.");
while (scanner.hasNext()) {
System.out.println(scanner.next());
}
result:
my
name
is
budi
// split string by regex (zero or one comma) and a space
Scanner scanner1 = new Scanner("1 isn't true, 0 isn't false, 2.0 is double");
scanner1.useDelimiter("[,]? ");
while (scanner1.hasNext()) {
// is the next token can be converted to int
if (scanner1.hasNextInt()) {
System.out.println("Found int : " + scanner1.nextInt());
// is the next token can be converted to boolean
} else if (scanner1.hasNextBoolean()) {
System.out.println("Found boolean : " + scanner1.nextBoolean());
// is the next token can be converted to double
} else if (scanner1.hasNextDouble()) {
System.out.println("Found double : " + scanner1.nextDouble());
} else {
System.out.println(scanner1.next());
}
}
result:
Found int : 1
isn't
Found boolean : true
Found int : 0
isn't
Found boolean : false
Found double : 2.0
is
double
SCJP 6 Part VII - Regex
Pattern pattern = Pattern.compile("aba");
Matcher matcher = pattern.matcher("abababababababa");
while (matcher.find()) {
System.out.println("aba has been found at index : " + matcher.start() + " " + matcher.group());
}
result:
aba has been found at index : 0 aba
aba has been found at index : 4 aba
aba has been found at index : 8 aba
aba has been found at index : 12 aba
Pattern pattern1 = Pattern.compile("\\d");
Matcher matcher1 = pattern1.matcher("jatim1");
while (matcher1.find()) {
System.out.println("a digit has been found at index : " + matcher1.start() + " " + matcher1.group());
}
result:
a digit has been found at index : 5 1
Pattern pattern2 = Pattern.compile("\\s");
Matcher matcher2 = pattern2.matcher("my name is ...");
while (matcher2.find()) {
System.out.println("a space has been found at index : " + matcher2.start());
}
result:
a space has been found at index : 2
a space has been found at index : 7
a space has been found at index : 10
Pattern pattern3 = Pattern.compile("\\w");
Matcher matcher3 = pattern3.matcher("123 -> lets go");
while (matcher3.find()) {
System.out.println("a letter or a digit or an underscore has been found at index : " + matcher3.start() + " " + matcher3.group());
}
result:
a letter or a digit or an underscore has been found at index : 0 1
a letter or a digit or an underscore has been found at index : 1 2
a letter or a digit or an underscore has been found at index : 2 3
a letter or a digit or an underscore has been found at index : 7 l
a letter or a digit or an underscore has been found at index : 8 e
a letter or a digit or an underscore has been found at index : 9 t
a letter or a digit or an underscore has been found at index : 10 s
a letter or a digit or an underscore has been found at index : 12 g
a letter or a digit or an underscore has been found at index : 13 o
Pattern pattern4 = Pattern.compile("[ap]");
Matcher matcher4 = pattern4.matcher("al pacino");
while (matcher4.find()) {
System.out.println("character 'a' or 'p' has been found at index : " + matcher4.start() + " " + matcher4.group());
}
result:
character 'a' or 'p' has been found at index : 0 a
character 'a' or 'p' has been found at index : 3 p
character 'a' or 'p' has been found at index : 4 a
Pattern pattern5 = Pattern.compile("[a-l]");
Matcher matcher5 = pattern5.matcher("al pacino");
while (matcher5.find()) {
System.out.println("character 'a' until 'l' has been found at index : " + matcher5.start() + " " + matcher5.group());
}
result:
character 'a' until 'l' has been found at index : 0 a
character 'a' until 'l' has been found at index : 1 l
character 'a' until 'l' has been found at index : 4 a
character 'a' until 'l' has been found at index : 5 c
character 'a' until 'l' has been found at index : 6 i
Pattern pattern6 = Pattern.compile("[a-lA-L]");
Matcher matcher6 = pattern6.matcher("aL PaCiNo");
while (matcher6.find()) {
System.out.println("character 'a' until 'l' OR 'A' until 'L' has been found at index : " + matcher6.start() + " " + matcher6.group());
}
return:
character 'a' until 'l' OR 'A' until 'L' has been found at index : 0 a
character 'a' until 'l' OR 'A' until 'L' has been found at index : 1 L
character 'a' until 'l' OR 'A' until 'L' has been found at index : 4 a
character 'a' until 'l' OR 'A' until 'L' has been found at index : 5 C
character 'a' until 'l' OR 'A' until 'L' has been found at index : 6 i
Pattern pattern7 = Pattern.compile("\\d+");
Matcher matcher7 = pattern7.matcher("(031) 531 4249");
while (matcher7.find()) {
System.out.println("a group of digit has been found at index : " + matcher7.start() + " " + matcher7.group());
}
result (+ means one or more, \\d+ means one or more digit):
a group of digit has been found at index : 1 031
a group of digit has been found at index : 6 531
a group of digit has been found at index : 10 4249
Pattern pattern8 = Pattern.compile("0[xX]([0-9a-fA-F])+");
Matcher matcher8 = pattern8.matcher("0xffffff 0X778899 0X1 0XXX");
while (matcher8.find()) {
System.out.println("a hexadecimal has been found at index : " + matcher8.start() + " " + matcher8.group());
}
result:
a hexadecimal has been found at index : 0 0xffffff
a hexadecimal has been found at index : 9 0X778899
a hexadecimal has been found at index : 18 0X1
Pattern pattern9 = Pattern.compile("\\(\\d\\d\\d\\)([-\\s])?\\d\\d\\d([-\\s]?)\\d\\d\\d\\d");
Matcher matcher9 = pattern9.matcher("(031)-5314249, (031) 5314249, (031)5314249, (031)-531-4249, (031)-531 4249, (031) 531-42490000");
while (matcher9.find()) {
System.out.println("a valid phone number has been found at index : " + matcher9.start() + " " + matcher9.group());
}
result (? means zero or one, ([-\\s])? means zero or one either - or space):
a valid phone number has been found at index : 0 (031)-5314249
a valid phone number has been found at index : 15 (031) 5314249
a valid phone number has been found at index : 30 (031)5314249
a valid phone number has been found at index : 44 (031)-531-4249
a valid phone number has been found at index : 60 (031)-531 4249
a valid phone number has been found at index : 76 (031) 531-4249
Pattern pattern10 = Pattern.compile("[iI][nN][dD][oO]([a-zA-Z])*");
Matcher matcher10 = pattern10.matcher("Indonesia India indo123 indochina indo");
while (matcher10.find()) {
System.out.println("a string start with indo has been found at index : " + matcher10.start() + " " + matcher10.group());
}
result (* means zero or more):
a string start with indo has been found at index : 0 Indonesia
a string start with indo has been found at index : 16 indo
a string start with indo has been found at index : 24 indochina
a string start with indo has been found at index : 34 indo
Pattern pattern11 = Pattern.compile("f...");
Matcher matcher11 = pattern11.matcher("fool feel fast fame fee flash");
while (matcher11.find()) {
System.out.println(". is used to find any single char : " + matcher11.start() + " " + matcher11.group());
}
result:
. is used to find any single char : 0 fool
. is used to find any single char : 5 feel
. is used to find any single char : 10 fast
. is used to find any single char : 15 fame
. is used to find any single char : 20 fee
. is used to find any single char : 24 flas
Matcher matcher = pattern.matcher("abababababababa");
while (matcher.find()) {
System.out.println("aba has been found at index : " + matcher.start() + " " + matcher.group());
}
result:
aba has been found at index : 0 aba
aba has been found at index : 4 aba
aba has been found at index : 8 aba
aba has been found at index : 12 aba
Pattern pattern1 = Pattern.compile("\\d");
Matcher matcher1 = pattern1.matcher("jatim1");
while (matcher1.find()) {
System.out.println("a digit has been found at index : " + matcher1.start() + " " + matcher1.group());
}
result:
a digit has been found at index : 5 1
Pattern pattern2 = Pattern.compile("\\s");
Matcher matcher2 = pattern2.matcher("my name is ...");
while (matcher2.find()) {
System.out.println("a space has been found at index : " + matcher2.start());
}
result:
a space has been found at index : 2
a space has been found at index : 7
a space has been found at index : 10
Pattern pattern3 = Pattern.compile("\\w");
Matcher matcher3 = pattern3.matcher("123 -> lets go");
while (matcher3.find()) {
System.out.println("a letter or a digit or an underscore has been found at index : " + matcher3.start() + " " + matcher3.group());
}
result:
a letter or a digit or an underscore has been found at index : 0 1
a letter or a digit or an underscore has been found at index : 1 2
a letter or a digit or an underscore has been found at index : 2 3
a letter or a digit or an underscore has been found at index : 7 l
a letter or a digit or an underscore has been found at index : 8 e
a letter or a digit or an underscore has been found at index : 9 t
a letter or a digit or an underscore has been found at index : 10 s
a letter or a digit or an underscore has been found at index : 12 g
a letter or a digit or an underscore has been found at index : 13 o
Pattern pattern4 = Pattern.compile("[ap]");
Matcher matcher4 = pattern4.matcher("al pacino");
while (matcher4.find()) {
System.out.println("character 'a' or 'p' has been found at index : " + matcher4.start() + " " + matcher4.group());
}
result:
character 'a' or 'p' has been found at index : 0 a
character 'a' or 'p' has been found at index : 3 p
character 'a' or 'p' has been found at index : 4 a
Pattern pattern5 = Pattern.compile("[a-l]");
Matcher matcher5 = pattern5.matcher("al pacino");
while (matcher5.find()) {
System.out.println("character 'a' until 'l' has been found at index : " + matcher5.start() + " " + matcher5.group());
}
result:
character 'a' until 'l' has been found at index : 0 a
character 'a' until 'l' has been found at index : 1 l
character 'a' until 'l' has been found at index : 4 a
character 'a' until 'l' has been found at index : 5 c
character 'a' until 'l' has been found at index : 6 i
Pattern pattern6 = Pattern.compile("[a-lA-L]");
Matcher matcher6 = pattern6.matcher("aL PaCiNo");
while (matcher6.find()) {
System.out.println("character 'a' until 'l' OR 'A' until 'L' has been found at index : " + matcher6.start() + " " + matcher6.group());
}
return:
character 'a' until 'l' OR 'A' until 'L' has been found at index : 0 a
character 'a' until 'l' OR 'A' until 'L' has been found at index : 1 L
character 'a' until 'l' OR 'A' until 'L' has been found at index : 4 a
character 'a' until 'l' OR 'A' until 'L' has been found at index : 5 C
character 'a' until 'l' OR 'A' until 'L' has been found at index : 6 i
Pattern pattern7 = Pattern.compile("\\d+");
Matcher matcher7 = pattern7.matcher("(031) 531 4249");
while (matcher7.find()) {
System.out.println("a group of digit has been found at index : " + matcher7.start() + " " + matcher7.group());
}
result (+ means one or more, \\d+ means one or more digit):
a group of digit has been found at index : 1 031
a group of digit has been found at index : 6 531
a group of digit has been found at index : 10 4249
Pattern pattern8 = Pattern.compile("0[xX]([0-9a-fA-F])+");
Matcher matcher8 = pattern8.matcher("0xffffff 0X778899 0X1 0XXX");
while (matcher8.find()) {
System.out.println("a hexadecimal has been found at index : " + matcher8.start() + " " + matcher8.group());
}
result:
a hexadecimal has been found at index : 0 0xffffff
a hexadecimal has been found at index : 9 0X778899
a hexadecimal has been found at index : 18 0X1
Pattern pattern9 = Pattern.compile("\\(\\d\\d\\d\\)([-\\s])?\\d\\d\\d([-\\s]?)\\d\\d\\d\\d");
Matcher matcher9 = pattern9.matcher("(031)-5314249, (031) 5314249, (031)5314249, (031)-531-4249, (031)-531 4249, (031) 531-42490000");
while (matcher9.find()) {
System.out.println("a valid phone number has been found at index : " + matcher9.start() + " " + matcher9.group());
}
result (? means zero or one, ([-\\s])? means zero or one either - or space):
a valid phone number has been found at index : 0 (031)-5314249
a valid phone number has been found at index : 15 (031) 5314249
a valid phone number has been found at index : 30 (031)5314249
a valid phone number has been found at index : 44 (031)-531-4249
a valid phone number has been found at index : 60 (031)-531 4249
a valid phone number has been found at index : 76 (031) 531-4249
Pattern pattern10 = Pattern.compile("[iI][nN][dD][oO]([a-zA-Z])*");
Matcher matcher10 = pattern10.matcher("Indonesia India indo123 indochina indo");
while (matcher10.find()) {
System.out.println("a string start with indo has been found at index : " + matcher10.start() + " " + matcher10.group());
}
result (* means zero or more):
a string start with indo has been found at index : 0 Indonesia
a string start with indo has been found at index : 16 indo
a string start with indo has been found at index : 24 indochina
a string start with indo has been found at index : 34 indo
Pattern pattern11 = Pattern.compile("f...");
Matcher matcher11 = pattern11.matcher("fool feel fast fame fee flash");
while (matcher11.find()) {
System.out.println(". is used to find any single char : " + matcher11.start() + " " + matcher11.group());
}
result:
. is used to find any single char : 0 fool
. is used to find any single char : 5 feel
. is used to find any single char : 10 fast
. is used to find any single char : 15 fame
. is used to find any single char : 20 fee
. is used to find any single char : 24 flas
Subscribe to:
Posts (Atom)