Android String Clone cloneString(String value)

Here you can find the source of cloneString(String value)

Description

Create a new String instance based on an input String.

Parameter

Parameter Description
value The value to clone

Return

The cloned version of the input value.

Declaration

public static final String cloneString(String value) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w ww  . j  a va  2  s .c om
     * Create a new String instance based on an input String.
     * The String class tends to have these fancy ways of re-using internal
     * data structures when creating one string from another. This method
     * circumvents those optimisations.
     * @param value The value to clone
     * @return The cloned version of the input value.
     */
    public static final String cloneString(String value) {
        char[] chars = value.toCharArray();
        char[] ret = new char[chars.length];
        System.arraycopy(chars, 0, ret, 0, chars.length);
        return new String(ret);
    }
}