diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ListFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ListFormat.java index 06f12d5a82..1fa83909ca 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/ListFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ListFormat.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2012-2012, Google, International Business Machines Corporation and * + * Copyright (C) 2012-2012, Google, International Business Machines Corporation and * others. All Rights Reserved. * ******************************************************************************* */ @@ -131,8 +131,14 @@ final public class ListFormat implements Transform<Collection<String>, String> { } private String format2(String pattern, Object a, Object b) { - // TODO: make slightly faster by using single pass. - return pattern.replace("{0}", a.toString()).replace("{1}", b.toString()); + int i0 = pattern.indexOf("{0}"); + int i1 = pattern.indexOf("{1}"); + if (i0 < 0 || i1 < 0) { + throw new IllegalArgumentException("Missing {0} or {1} in pattern " + pattern); + } + return i0 < i1 + ? pattern.substring(0, i0) + a + pattern.substring(i0+3, i1) + b + pattern.substring(i1+3) + : pattern.substring(0, i1) + a + pattern.substring(i1+3, i0) + b + pattern.substring(i0+3); } /** diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ListFormatTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ListFormatTest.java index e790e9791d..f1d9c103ee 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ListFormatTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/ListFormatTest.java @@ -1,16 +1,12 @@ /* ******************************************************************************* - * Copyright (C) 2012-2012, Google, International Business Machines Corporation and * + * Copyright (C) 2012-2012, Google, International Business Machines Corporation and * others. All Rights Reserved. * ******************************************************************************* */ package com.ibm.icu.dev.test.util; -import java.util.Arrays; -import java.util.Collection; - import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.text.Transform; import com.ibm.icu.util.ListFormat; import com.ibm.icu.util.ULocale;