Question: product model :

```
public class product {
    private String productName;
    private String productCategory;
    private String productDescription;
    private double productPrice;
    private String productCondition;
    private String productStatus;
    private int unitInStatus;
    private String productManufacturer;

```

getter and setters
.
.
.

DAO:

```
String myString="عروسک خرس";
    byte[] ptext=myString.getBytes("UTF-8");
    String out=new String(ptext,"UTF-8");
    product1.setProductName(out);

    product1.setProductCategory("عروسک");
    product1.setProductDescription("عرسک پول?ش? قابل شستشو");

```

jsp :

```
<td>${product.productName}</td>
   <td>${product.productCategory}</td>
   <td>${product.productCondition}</td>
   <td>${product.productPrice}</td>

```

result :

```
نام محصول   دسته    شریایظ  (تومان) قیمت
���Ә ���    ���Ә    ��?�    15000.0

```

Answer: 
`sorted` can provide a custom sort condition for example (assuming that all strings are not empty)

```
let array = ["c_572A267C-DAC8-487D-B1AF-719FE8E3A6AB_FF6E00_2", "b_69E21DC6-431C-4373-B4F1-90BF7FB5462B_FFC000_1"]
let sortedArray = array.sorted { $0.substring(from: $0.index(before: $0.endIndex)) < $1.substring(from: $1.index(before: $1.endIndex)) }

```

Swift 3+ the syntax is much more convenient

```
let array = ["c_572A267C-DAC8-487D-B1AF-719FE8E3A6AB_FF6E00_2", "b_69E21DC6-431C-4373-B4F1-90BF7FB5462B_FFC000_1"]
let sortedArray = array.sorted { $0.suffix(1) < $1.suffix(1) }

```
One more answer with `Higher Order Function`:

> 
> 1. Reverse Each word in an `Array`
> 2. Then, Sort
> 
> 
> 

```
let arr = ["c_572A267C-DAC8-487D-B1AF-719FE8E3A6AB_FF6E00_2",
               "b_69E21DC6-431C-4373-B4F1-90BF7FB5462B_FFC000_1"]

```

**One Line:**

```
let returnValue = arr.map({String($0.reversed())}).sorted().map({String($0.reversed())})

```

**Multi Line:**

```
let reverseEachWordsArr = arr.map { value in
    return String(value.reversed())
}

let finalCharSortArr = reverseEachWordsArr.sorted().map { word  in
    return String(word.reversed())
}
print(finalCharSortArr)

```

OUTPUT:

```
["b_69E21DC6-431C-4373-B4F1-90BF7FB5462B_FFC000_1", 
 "c_572A267C-DAC8-487D-B1AF-719FE8E3A6AB_FF6E00_2"]

```