Results 1 to 4 of 4
- 10-28-2009, 03:59 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 10
- Rep Power
- 0
How does the '*' work in the code?
import java.util.regex.*;
class Regex2 {
public static void main(String[] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
boolean b = false;
while(b = m.find()) {
System.out.print(m.start() + m.group());
}
}
}
And the command line:
java Regex2 "\d*" ab34ef
What is the result?
A. 234
B. 334
C. 2334
D. 0123456
E. 01234456
F. 12334567
G. Compilation fails
- 10-28-2009, 06:56 AM #2
Which one, the one in the import statement, or the command-line input?
In the import statement, it's a "star import" - it imports ALL classes in that package. However, it can get you into trouble if two packages have the same class. I saw someone do this by importing java.awt.* and java.util.*. Both have a "List" class, and you can't import two classes with the same name, because the compiler can't figure out which you intended. Also, when working with an IDE (e.g. Eclipse, NetBeans), I've heard star imports can cause problems. I don't use them, I let the IDE import the necessary classes for me, so I'm not sure what kind of problems, or how they occur.
As for the star in the command-line, when it's compiled in the regex, it means "0 or more (of the previous element)". So, in the code above, it means 0 or more digits.Last edited by CodesAway; 10-28-2009 at 07:05 AM.
CodesAway - codesaway.info
writing tools that make writing code a little easier
- 10-28-2009, 09:22 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 10
- Rep Power
- 0
Commandline...
thanks. :)
- 10-28-2009, 09:26 AM #4
Welcome.
If you're unfamiliar with regex syntax, check out regular-expressions.info/, which has an amazing regular expression tutorial.CodesAway - codesaway.info
writing tools that make writing code a little easier
Similar Threads
-
need to adjust a code I have to work with hidden fields
By carag in forum New To JavaReplies: 2Last Post: 07-29-2009, 12:23 PM -
Running .java-files won't work/compile does!(Code inside)
By wyldstyle in forum New To JavaReplies: 6Last Post: 02-06-2009, 08:05 PM -
how does this code work...explain me the execution please...
By vital parsley in forum New To JavaReplies: 3Last Post: 07-25-2008, 04:50 AM -
the code dosent work
By pcman in forum Java 2DReplies: 1Last Post: 03-20-2008, 08:20 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks