Here you can find the source of internStringsInList(List
public static List<String> internStringsInList(List<String> list)
//package com.java2s; /*/*from www . ja v a 2 s .c o m*/ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.List; import java.util.ListIterator; public class Main { /** * This method interns all the strings in the given list in place. That is, * it iterates over the list, replaces each element with the interned copy * and eventually returns the same list. * * Note that the provided List implementation should return an iterator * (via list.listIterator()) method, and that iterator should implement * the set(Object) method. That's what all List implementations in the JDK * provide. However, if some custom List implementation doesn't have this * functionality, this method will return without interning its elements. */ public static List<String> internStringsInList(List<String> list) { if (list != null) { try { ListIterator<String> it = list.listIterator(); while (it.hasNext()) { it.set(it.next().intern()); } } catch (UnsupportedOperationException e) { } // set() not implemented - ignore } return list; } }