3

I had this:

Comparator<Item> ignoreLeadingThe = new Comparator<Item>() {
                public int compare(Item a, Item b) {
                    String newA = a.name.replaceAll("(?i)^the\\s+", "");
                    String newB = b.name.replaceAll("(?i)^the\\s+", "");
                    return newA.compareToIgnoreCase(newB);
                }
            };

Array.sort(MyItemArrayOfObjects, ignoreLeadingThe);

I stopped using Arrays and am now using ArrayList. So when I do this:

Collections.sort(MyItemArrayListOfObjects, ignoreLeadingThe);

I can't even figure out the pattern that it is now sorting by. Can I do a clean switch like this? (It is entirely possible I broke this with something not mentioned above, if this is right, then that's all I need to know)

Note: Originally, with the Arrays I was simply trying to alphabetize a list and ignore the leading "The". It's for an Android app. Each List row Item data was wrapped in an Object that I am passing to an ArrayAdapter. I simply wanted to take an ArrayList inside that object and alphabetize it. So essentially, it's an ArrayList with a few ArrayList inside it.


You will need a server-side technology to accept the image.

On the server-side you will need to save the image somewhere.

Then, either through AJAX or by reloading the page, you need to embed an img-tag pointing at the image on the server

4

2 に答える 2

1

あなたのコンパレータは良さそうです

悪いニュースは、結果の文字列をキャッシュしないことです。したがって、並べ替えによりo(N*log(N))、パターン、マッチャー、および文字列のオブジェクトが作成されますが、それらのいくつかの作成が超高速ではないという事実については話していません。

UPD

インターフェイスに実装するメソッドで @Override を使用し、サブクラスでオーバーライドすることをお勧めします。

于 2013-04-15T00:48:34.927 に答える