Creating Strings in Java

You may have noticed that you can combine strings with the + operator in Java, just as you can in JavaScript:

public class app
{
    public static void main(String[] args)
    {
        double chargesDue[][] = {{1093.66, 667.19, 45.99, 890.30, 99.06},
                                 {2019.00, 129.99, 19.01, 630.90, 23.17}};

        System.out.println("Customer 4 owes $" +
            chargesDue[0][4] + " in the eastern branch.");
        System.out.println("Customer 4 owes $" +
            chargesDue[1][4] + " in the western branch.");
    }
}

The reason this works is that strings are supported by the built-in class String in Java. In fact, the String class is treated in a special way in Java, and you can use it just as you would any built-in data type, as in the following case. (Note that I don't have to ...

Get Inside XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.