This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Here is my situation, I have a Java program that prints out a table and sends it to a jsp. The table prints out how many hours someone works from Date-Date. I need to do columns for each day. So it looks something like:
I aleady have the name company hours done, problem is, is that the days are dynamic. I need to be able to select from a different range of dates not always the 15-18. So how can I add a column to a table with a loop? Here is what the current code looks like:
It's a little bit tricky sometimes, but yes. The "+" operator can catenate Strings together. It can also catenate Strings to other things -- for example, a String and an Object. It does this by converting the other thing to a String first (for an object, by using the toString() method; for primitives like ints, by using static methods like String.valueOf(int).)
But it can't catenate (for example) two Object objects, and it adds numbers rather than catenating them. One operand of "+" must be a String for this operator to imply String catenation, and remember that Java expressions are always evaluated left-to-right.
So be careful. This prints "foo12":
System.out.println("foo" + 1 + 2);
while this prints "3foo":
System.out.println(1 + 2 + foo);
System.out.println("foo" + new Object() + new Object());
while this doesn't:
System.out.println(new Object() + new Object() + "foo");