Results 1 to 4 of 4
- 09-19-2012, 07:03 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
match evaluation vs. pre increment
vs.Java Code:"7.07".substring(0,1).matches("[0-9]");
The first expression is true, the second is false. Why.Java Code:int i=0;"7.07".substring(i,++i).matches("[0-9]")
To clarify, I expected that ++i would be executed before the substring was calculated and matched.
- 09-19-2012, 08:06 PM #2
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
Re: match evaluation vs. pre increment
I ran the following code and got true for both...
Java Code:package test; public class Main { public static void main(String[] args) { boolean test1; boolean test2; test1 = "7.07".substring(0,1).matches("[0-9]"); int i=0; test2 = "7.07".substring(i,++i).matches("[0-9]"); System.out.println(test1); System.out.println(test2); } }
- 09-19-2012, 10:01 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 6
- Rep Power
- 0
Re: match evaluation vs. pre increment
Thank you for your reply. Your code runs both times true on my machine too now. My code did return false however, it was inside a loop. I still have it in my display screen in eclipse
"7.07".substring(firstDigitIndex, ++firstDigitIndex).matches("[0-9]")
(boolean) false
Very suspicious.
- 09-19-2012, 10:36 PM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Similar Threads
-
Increment Counter for ID
By blkshrk81 in forum New To JavaReplies: 6Last Post: 12-01-2010, 01:25 AM -
Increment Operator Example
By abimaran in forum New To JavaReplies: 10Last Post: 11-03-2009, 04:45 PM -
Increment a Variable
By rhm54 in forum New To JavaReplies: 2Last Post: 06-14-2008, 02:57 AM -
How to create auto-increment
By Albert in forum JDBCReplies: 2Last Post: 07-04-2007, 05:23 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks