String concatenation in EL for dynamic ResourceBundle key

If you’re already on Servlet 3.1 / EL 3.0 (Tomcat 8, WildFly 8, GlassFish 4, etc), make use of new EL 3.0 += operator: <h:outputText value=”#{msg[‘entry’ += managedBean.entryIndex]}” /> If you’re only on Servlet 3.0 / EL 2.2 (Tomcat 7, JBoss AS 6/7, GlassFish 3, etc), make use of new EL 2.2 ability to directly … Read more

JavaScript String concatenation behavior with null or undefined values

You can use Array.prototype.join to ignore undefined and null: [‘a’, ‘b’, void 0, null, 6].join(”); // ‘ab6’ According to the spec: If element is undefined or null, Let next be the empty String; otherwise, let next be ToString(element). Given that, What is the history behind the oddity that makes JS converting null or undefined to … Read more

Does concatenating strings in Java always lead to new strings being created in memory?

I realized that the second way uses string concatenation and will create 5 new strings in memory and this might lead to a performance hit. No it won’t. Since these are string literals, they will be evaluated at compile time and only one string will be created. This is defined in the Java Language Specification … Read more

How to concatenate strings with padding in sqlite

The || operator is “concatenate” – it joins together the two strings of its operands. From http://www.sqlite.org/lang_expr.html For padding, the seemingly-cheater way I’ve used is to start with your target string, say ‘0000’, concatenate ‘0000423’, then substr(result, -4, 4) for ‘0423’. Update: Looks like there is no native implementation of “lpad” or “rpad” in SQLite, … Read more

Using LINQ to concatenate strings

This answer shows usage of LINQ (Aggregate) as requested in the question and is not intended for everyday use. Because this does not use a StringBuilder it will have horrible performance for very long sequences. For regular code use String.Join as shown in the other answer Use aggregate queries like this: string[] words = { … Read more

Android TextView : “Do not concatenate text displayed with setText”

Resource has the get overloaded version of getString which takes a varargs of type Object: getString(int, java.lang.Object…). If you setup correctly your string in strings.xml, with the correct place holders, you can use this version to retrieve the formatted version of your final String. E.g. <string name=”welcome_messages”>Hello, %1$s! You have %2$d new messages.</string> using getString(R.string.welcome_message, … Read more