Currently, I am learning the function of distinct() using in same lambda expression: The first one is used for finding the distinct digit of an integer
Integer intVar = 12341234;
long c1 = intVar.toString().chars().distinct().count(); // (1,2,3,4)
System.out.println(c1);//result = 4
Then i want to try find the same thing within a range, My thought is:
1.loop from 1 to 1_000_000
2.filter isSquareNumber && <= 9_999_999 && 1_000_000
3.convert to char
4.distinct
5.store as list(key,value)
6.findfirst key with value=7
Because the original code works but looks awful
int inte = IntStream.iterate(1, i-> i + 1)
.filter(i->isSquareNumber(i) && i<= 9999999 && i>=1000000)
.filter(i-> i%10!=i/10%10 && i%10!=i/100%10 && i%10!=i/1000%10 && i%10!=i/10000%10 && i%10!=i/100000%10 && i%10!=i/1000000%10)
.filter(i-> i/10%10!=i/100%10 && i/10%10!=i/1000%10 && i/10%10!=i/10000%10 && i/10%10!=i/100000%10 && i/10%10!=i/1000000%10)
.filter(i-> i/100%10!=i/1000%10 && i/100%10!=i/10000%10 && i/100%10!=i/100000%10 && i/100%10!=i/1000000%10)
.filter(i-> i/1000%10!=i/10000%10 && i/1000%10!=i/100000%10 && i/1000%10!=i/1000000%10)
.filter(i-> i/10000%10!=i/10%10 && i/10000%10!=i/100000%10)
.filter(i-> i/100000%10!=i/1000000%10)
.findFirst()
.getAsInt();
System.out.println(inte);//result = 1034289
WJS helped version
IntStream
.iterate(1, i-> i + 1)
.filter(i->isSquareNumber(i) && i<= 9999999 && i>=1000000)
.mapToObj(i->new String[] {Integer.toString(i), Arrays
.stream(Integer.toString(i).split(""))
.filter(a -> a[1].length() >= 7)
.findFirst()
.ifPresent(a -> System.out
.println(a[1] + " --> " + a[1].length()));
It works wonderfully. And now I am trying to move one more step that creates a method in which the return type is an integer and returns the most distinct digit integer, but not a boolean.