本文整理了Java中java.lang.String.intern()
方法的一些代码示例,展示了String.intern()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.intern()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:intern
[英]Returns a canonical representation for the string object.
A pool of strings, initially empty, is maintained privately by the class String
.
When the intern method is invoked, if the pool already contains a string equal to this String
object as determined by the #equals(Object) method, then the string from the pool is returned. Otherwise, this String
object is added to the pool and a reference to this String
object is returned.
It follows that for any two strings s
and t
, s.intern() == t.intern()
is true
if and only if s.equals(t)
is true
.
All literal strings and string-valued constant expressions are interned. String literals are defined in section 3.10.5 of the The Java™ Language Specification.
[中]返回字符串对象的规范表示形式。
字符串池最初为空,由类String
私有维护。
调用intern方法时,如果池中已经包含一个字符串,该字符串等于由#equals(object)方法确定的String
对象,则返回池中的字符串。否则,此String
对象将添加到池中,并返回对此String
对象的引用。
因此,对于任何两个字符串s
和t
,当且仅当s.equals(t)
为true
时,s.intern() == t.intern()
为true
。
所有文字字符串和字符串值常量表达式都被插入。字符串文本在Java的第3.10.5节中定义™ 语言规范。
代码示例来源:origin: stackoverflow.com
String str=readString(); // read lengthy string any source db,textbox/jsp etc..
// This will place the string in memory pool from which you cant remove
str.intern();
代码示例来源:origin: stanfordnlp/CoreNLP
private String intern(String s) {
if (flags.intern) {
return s.intern();
} else {
return s;
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
private String intern(String s) {
if (flags.intern) {
return s.intern();
} else {
return s;
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public ExtractionObject(String objectId,
CoreMap sentence,
Span span,
String type,
String subtype) {
this.objectId = objectId;
this.sentence = sentence;
this.extentTokenSpan = span;
this.type = type.intern();
this.subType = (subtype != null ? subtype.intern() : null);
this.attributeMap = null;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private String intern(String s) {
if (globalFlags.intern) {
return s.intern();
}
return s;
}
代码示例来源:origin: stanfordnlp/CoreNLP
private void internStrings() {
if (first != null) {
first = first.intern();
}
if (second != null) {
second = second.intern();
}
}
代码示例来源:origin: iBotPeaches/Apktool
private void checkInterning(String name) {
if (namesInterned && name != name.intern()) {
throw new IllegalArgumentException(
"all names passed as arguments must be interned"
+ "when NAMES INTERNED feature is enabled");
}
}
代码示例来源:origin: jenkinsci/jenkins
/**
* Null-safe String intern method.
* @return A canonical representation for the string object. Null for null input strings
*/
@Nullable
public static String intern(@CheckForNull String s) {
return s==null ? s : s.intern();
}
代码示例来源:origin: Netflix/zuul
public HeaderName(String name)
{
if (name == null) throw new NullPointerException("HeaderName cannot be null!");
this.name = SHOULD_INTERN ? name.intern() : name;
this.normalised = SHOULD_INTERN ? name.toLowerCase().intern() : name.toLowerCase();
}
代码示例来源:origin: prestodb/presto
private static void addNumerals(TreeMap<String, Integer> map, int start, int end, Integer[] integers) {
for (int i=start; i<=end; i++) {
map.put(String.valueOf(i).intern(), integers[i]);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
private void addAllInterningAndPrefixing(Collection<String> accumulator, Collection<String> addend, String prefix) {
assert prefix != null;
for (String protoFeat : addend) {
if ( ! prefix.isEmpty()) {
protoFeat = prefix + protoFeat;
}
if (globalFlags.intern) {
protoFeat = protoFeat.intern();
}
accumulator.add(protoFeat);
}
}
代码示例来源:origin: jenkinsci/jenkins
/** Share data structure with other builds, mainly those of the same job. */
private PackedMap<String,String> compact(Map<String,String> record) {
Map<String,String> b = new HashMap<String,String>();
for (Entry<String,String> e : record.entrySet()) {
b.put(e.getKey().intern(), e.getValue().intern());
}
return PackedMap.of(b);
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Normalizes a nonterminal contents.
* This implementation strips functional tags, etc. and interns the
* nonterminal.
*/
@Override
public String normalizeNonterminal(String category) {
return cleanUpLabel(category).intern();
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Normalizes a nonterminal contents.
* This implementation strips functional tags, etc. and interns the
* nonterminal.
*/
@Override
public String normalizeNonterminal(String category) {
return cleanUpLabel(category).intern();
}
代码示例来源:origin: alibaba/canal
protected String getFullName(String schemaName, String tableName) {
StringBuilder sb = new StringBuilder();
if (schemaName != null) {
sb.append(appendEscape(schemaName)).append(DOT);
}
sb.append(appendEscape(tableName));
return sb.toString().intern();
}
代码示例来源:origin: alibaba/canal
public String getSelectSql(String schemaName, String tableName, String[] pkNames, String[] columnNames) {
StringBuilder sql = new StringBuilder("select ");
int size = columnNames.length;
for (int i = 0; i < size; i++) {
sql.append(appendEscape(columnNames[i])).append((i + 1 < size) ? " , " : "");
}
sql.append(" from ").append(getFullName(schemaName, tableName)).append(" where ( ");
appendColumnEquals(sql, pkNames, "and");
sql.append(" ) ");
return sql.toString().intern();// 不使用intern,避免方法区内存消耗过多
}
代码示例来源:origin: alibaba/canal
public String getDeleteSql(String schemaName, String tableName, String[] pkNames) {
StringBuilder sql = new StringBuilder("delete from " + getFullName(schemaName, tableName) + " where ");
appendColumnEquals(sql, pkNames, "and");
return sql.toString().intern();// intern优化,避免出现大量相同的字符串
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* Removes duplicate graphs from the set, using the string form of the graph
* as the key (obviating issues with object equality).
*/
public static Collection<SemanticGraph> removeDuplicates(Collection<SemanticGraph> graphs) {
Map<String, SemanticGraph> map = Generics.newHashMap();
for (SemanticGraph sg : graphs) {
String keyVal = sg.toString().intern();
map.put(keyVal, sg);
}
return map.values();
}
代码示例来源:origin: alibaba/canal
public String getUpdateSql(String schemaName, String tableName, String[] pkNames, String[] columnNames) {
StringBuilder sql = new StringBuilder("update " + getFullName(schemaName, tableName) + " set ");
appendColumnEquals(sql, columnNames, ",");
sql.append(" where (");
appendColumnEquals(sql, pkNames, "and");
sql.append(")");
return sql.toString().intern(); // 不使用intern,避免方法区内存消耗过多
}
代码示例来源:origin: Netflix/zuul
public HeaderName(String name)
{
if (name == null) throw new NullPointerException("HeaderName cannot be null!");
this.name = SHOULD_INTERN ? name.intern() : name;
this.normalised = SHOULD_INTERN ? name.toLowerCase().intern() : name.toLowerCase();
}
内容来源于网络,如有侵权,请联系作者删除!