Java Reference
In-Depth Information
In the previous code, the loop generates a new sequence with only even members from the
original sequence, [ 2, 4, 6, 8, 10, 12, 14 ] , using the where clause to specify a
selection expression.
Also notice you can add more than one query in the loop expression where the result is a
Cartesian product of all subsets expressed in each query. For instance, the following will
produce 14 elements
var doublePoints = for(n in points where n mod 2 == 0,
i in [2,4]){
n * i
}
println (doublePoints);
This code loops over two sequences; the first sequence contains all even members of the
original points variable declared previously; the other is a two-member sequence containing
2 and 4, the loop generates new sequence [ 4, 8, 8, 16, 12, 24, 16, 32, 20,
40, 24, 48, 28, 56 ] .
Working with JavaFX String
String is a fundamental value type in JavaFX. Similar to Java and other languages on the
JVM, the String type is used to represent text literals within a single or double quotes.
Unlike Java, however, JavaFX strings have additional capabilities which will be explored
in this section.
Getting ready
You should be familiar with the notion of string literals and expressions.
How to do it...
We have already seen how to use String types in other recipes. When creating a String, you
simply create a literal or expression to represent the string's content, and use the curly braces
to embed expressions as shown below. The full listing for this code can be found in ch01/
source-code/src/javafx/StringDemo.fx .
var str1:String = "Hello World!";
var str2 = "Goodbye forever";
var title = "King";
println ("The {title} has arrived!");
var evens = [0, 2, 4, 6, 8];
println("What are the odds {for(d in evens) "{d + 1} "}");
var amount = 445234.66;
println ("Your house is worth ${%,.2f amount}");
 
Search WWH ::




Custom Search