java.util.Collections.replaceAll()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(255)

本文整理了Java中java.util.Collections.replaceAll()方法的一些代码示例,展示了Collections.replaceAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Collections.replaceAll()方法的具体详情如下:
包路径:java.util.Collections
类名称:Collections
方法名:replaceAll

Collections.replaceAll介绍

[英]Replaces all occurrences of Object obj in list with newObj. If the obj is null, then all occurrences of null are replaced with newObj.
[中]用newObj替换列表中所有出现的对象obj。如果obj为null,则所有出现的null都将替换为newObj。

代码示例

代码示例来源:origin: stackoverflow.com

List<String> list = Arrays.asList(
   "one", "two", "three", null, "two", null, "five"
 );
 System.out.println(list);
 // [one, two, three, null, two, null, five]
 Collections.replaceAll(list, "two", "one");
 System.out.println(list);
 // [one, one, three, null, one, null, five]
 Collections.replaceAll(list, "five", null);
 System.out.println(list);
 // [one, one, three, null, one, null, null]
 Collections.replaceAll(list, null, "none");
 System.out.println(list);
 // [one, one, three, none, one, none, none]

代码示例来源:origin: com.liferay.faces/com.liferay.faces.bridge.ext

@Override
public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
  Collections.replaceAll(childNodes, oldChild, newChild);
  return oldChild;
}

代码示例来源:origin: backport-util-concurrent/backport-util-concurrent

public static boolean replaceAll(List list, Object oldVal, Object newVal) {
  return java.util.Collections.replaceAll(list, oldVal, newVal);
}

代码示例来源:origin: org.codehaus.swizzle/swizzle-jirareport

public boolean replaceAll(List list, Object o, Object o1) {
  return Collections.replaceAll(list, o, o1);
}

代码示例来源:origin: stackoverflow.com

public void replaceVideo(Vector<Library> videos, Library current, Library newCopy)
{
 Collections.replaceAll(videos, current, newCopy);
}

代码示例来源:origin: stackoverflow.com

List<String> list = pmMap.get(value1);
if(list != null){
  Collections.replaceAll(list, value1, value2);
}

代码示例来源:origin: edu.emory.mathcs.backport/com.springsource.edu.emory.mathcs.backport

public static boolean replaceAll(List list, Object oldVal, Object newVal) {
  return java.util.Collections.replaceAll(list, oldVal, newVal);
}

代码示例来源:origin: spotify/styx

static List<String> argsReplace(List<String> template, String parameter) {
  List<String> result = new ArrayList<>(template);

  Collections.replaceAll(result, "{}", parameter);
  return result;
 }
}

代码示例来源:origin: apache/cloudstack

@Override
@ActionEvent(eventType = EventTypes.EVENT_FIREWALL_EGRESS_OPEN, eventDescription = "creating egress firewall rule for network", create = true)
public FirewallRule createEgressFirewallRule(FirewallRule rule) throws NetworkRuleConflictException {
  Account caller = CallContext.current().getCallingAccount();
  Network network = _networkDao.findById(rule.getNetworkId());
  if (network.getGuestType() == Network.GuestType.Shared) {
    throw new InvalidParameterValueException("Egress firewall rules are not supported for " + network.getGuestType() + "  networks");
  }
  List<String> sourceCidrs = rule.getSourceCidrList();
  if (sourceCidrs != null && !sourceCidrs.isEmpty())
  Collections.replaceAll(sourceCidrs, "0.0.0.0/0", network.getCidr());
  return createFirewallRule(null, caller, rule.getXid(), rule.getSourcePortStart(), rule.getSourcePortEnd(), rule.getProtocol(), sourceCidrs, rule.getDestinationCidrList(),
      rule.getIcmpCode(), rule.getIcmpType(), null, rule.getType(), rule.getNetworkId(), rule.getTrafficType(), rule.isDisplay());
}

代码示例来源:origin: stackoverflow.com

List<String> list = Arrays.asList(new String[] {"a","b"});      
System.out.println(list);
Collections.replaceAll(list, "a", "!!!!!");
System.out.println(list);

代码示例来源:origin: stackoverflow.com

String[] values= {null,"p", ";","z",null, "OR","y"};        
List<String> list=new ArrayList<String>(Arrays.asList(values));
Collections.replaceAll(list, null, "newVal");
values = list.toArray(new String[list.size()]);
System.out.println(Arrays.toString(values));

代码示例来源:origin: stackoverflow.com

List<String> lines = new ArrayList<String>();
lines.add("This");
lines.add("this");
lines.add("THIS");
lines.add("this won't work.");
Collections.replaceAll(lines, "this", "****");
System.out.println(lines);

代码示例来源:origin: stackoverflow.com

// let's say:
 // whole = "The city of San Francisco is truly beautiful!",
 // token = "San Francisco"
 public static String[] excludeString(String whole, String token) {
   // replaces token string "San Francisco" with "SanFrancisco"
   whole = whole.replaceAll(token, token.replaceAll("\\s+", ""));
   // splits whole string using space as delimiter, place tokens in a string array
   String[] strarr = whole.split("\\s+");
   // brings "SanFrancisco" back to "San Francisco" in strarr
   Collections.replaceAll(Arrays.asList(strarr), token.replaceAll("\\s+", ""), token);
   // returns the array of strings
   return strarr;
 }

代码示例来源:origin: org.talend.components/components-salesforce-runtime

public BulkResultSet getResultSet(InputStream input) throws IOException {
  CsvReader reader = new CsvReader(new InputStreamReader(input), getDelimitedChar(columnDelimiter));
  List<String> baseFileHeader = null;
  if (reader.readRecord()) {
    baseFileHeader = Arrays.asList(reader.getValues());
    Collections.replaceAll(baseFileHeader, "sf__Id", "salesforce_id");
    Collections.replaceAll(baseFileHeader, "sf__Created", "salesforce_created");
  }
  return new BulkResultSet(reader, baseFileHeader);
}

代码示例来源:origin: Talend/components

public BulkResultSet getResultSet(InputStream input) throws IOException {
  CsvReader reader = new CsvReader(new InputStreamReader(input), getDelimitedChar(columnDelimiter));
  List<String> baseFileHeader = null;
  if (reader.readRecord()) {
    baseFileHeader = Arrays.asList(reader.getValues());
    Collections.replaceAll(baseFileHeader, "sf__Id", "salesforce_id");
    Collections.replaceAll(baseFileHeader, "sf__Created", "salesforce_created");
  }
  return new BulkResultSet(reader, baseFileHeader);
}

代码示例来源:origin: Qihoo360/Quicksql

public static void collect(RexNode node, RexNode seek, Logic logic,
  List<Logic> logicList) {
 node.accept(new LogicVisitor(seek, logicList), logic);
 // Convert FALSE (which can only exist within LogicVisitor) to
 // UNKNOWN_AS_TRUE.
 Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE);
}

代码示例来源:origin: org.apache.calcite/calcite-core

public static void collect(RexNode node, RexNode seek, Logic logic,
  List<Logic> logicList) {
 node.accept(new LogicVisitor(seek, logicList), logic);
 // Convert FALSE (which can only exist within LogicVisitor) to
 // UNKNOWN_AS_TRUE.
 Collections.replaceAll(logicList, Logic.FALSE, Logic.UNKNOWN_AS_TRUE);
}

代码示例来源:origin: com.github.sommeri/less4j

public void replaceSelector(Selector oldSelector, Selector newSelector) {
 oldSelector.setParent(null);
 newSelector.setParent(this);
 
 Collections.replaceAll(this.selectors, oldSelector, newSelector);
}

代码示例来源:origin: AskNowQA/AutoSPARQL

public void replaceReferent(String ref1, String ref2) {
  Collections.replaceAll(m_Arguments,new DiscourseReferent(ref1),new DiscourseReferent(ref2));
}

代码示例来源:origin: locationtech/jts

public static Geometry replace(Geometry parent, Geometry original, Geometry replacement)
 {
  List elem = extractElements(parent, false);
  Collections.replaceAll(elem, original, replacement);
  return parent.getFactory().buildGeometry(elem);
 }
}

相关文章

Collections类方法