Swapping pairs of characters in a String
Using a StringBuffer for building the new string is good,
but the variable name str1 is non-descriptive.

The computation of the required array length can be shortened 
with the conditional operator:

int n = len % 2 == 0 ? len : len - 1;


Instead of swapping the array elements you can append them to the
string buffer in opposite order:

for (int i = 0; i &lt;= n - 2; i = i + 2) {
    str1 = str1.append(arr[i+1]).append(arr[i]);
}


(and the re-assignment to str1 is not necessary).

And now one sees that the intermediate array is not needed at all: 
You can append the swapped characters directly from the original string:

static String swapPairs(String str) {
    int len = str.length(); 
    StringBuffer swapped = new StringBuffer(len);
    for (int i = 0; i &lt; len - 1 ; i += 2) {
        swapped.append(str.charAt(i + 1));
        swapped.append(str.charAt(i));
    }
    if (len % 2 != 0) {
        swapped.append(str.charAt(len - 1));
    }
    return swapped.toString();
}