The second parameter String.substring(int, int) in Java is not a length - it is the (exceptional) upper bound of the index. If in .NET the second parameter String.substring(int, int) really a length.
So anytime you call foo.substring(x, y) in Java, which is equivalent to foo.Substring(x, y - x) in .NET ... and you really need to keep that in mind.
Itβs not entirely clear what you are trying to do, but your loop will not work in Java either. If you really want to just get one character from a string, just use the indexer along with % :
string text = "BCDABCD"; for (int i = 0; i < 63; i++) { Console.WriteLine(text[i % text.Length]); }
EDIT: Given the comment, I suspect you just want:
for (int i = 0; i < 63; i++) { Console.WriteLine("BCDABCD".Substring(3 - (j & 3), 4)); }
... in other words, the length will always be 4.
source share