java.util.Hashtable.put()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(129)

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

Hashtable.put介绍

[英]Associate the specified value with the specified key in this Hashtable. If the key already exists, the old value is replaced. The key and value cannot be null.
[中]将指定值与此哈希表中的指定键相关联。如果密钥已存在,则替换旧值。键和值不能为null。

代码示例

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

Properties props = new Properties();
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");  // If you need to authenticate
// Use the following if you need SSL
props.put("mail.smtp.socketFactory.port", d_port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

代码示例来源:origin: redisson/redisson

/**
 * Records the <code>$cflow</code> variable for the field specified
 * by <code>cname</code> and <code>fname</code>.
 *
 * @param name      variable name
 * @param cname     class name
 * @param fname     field name
 */
void recordCflow(String name, String cname, String fname) {
  if (cflow == null)
    cflow = new Hashtable();
  cflow.put(name, new Object[] { cname, fname });
}

代码示例来源:origin: wildfly/wildfly

/** {@inheritDoc} */
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
  final Object existing = environment.get(propName);
  environment.put(propName, propVal);
  return existing;
}

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

/**
 * Create a new JNDI initial context. Invoked by {@link #execute}.
 * <p>The default implementation use this template's environment settings.
 * Can be subclassed for custom contexts, e.g. for testing.
 *
 * @return the initial Context instance
 * @throws NamingException in case of initialization errors
 */
@SuppressWarnings({"unchecked"})
protected Context createInitialContext() throws NamingException {
  Properties env = getEnvironment();
  Hashtable icEnv = null;
  if (env != null) {
    icEnv = new Hashtable(env.size());
    for (Enumeration en = env.propertyNames(); en.hasMoreElements();) {
      String key = (String) en.nextElement();
      icEnv.put(key, env.getProperty(key));
    }
  }
  return new InitialContext(icEnv);
}

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

java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setPassword(password);
  System.err.println(jsche.getLocalizedMessage());
} catch (IOException ioe) {
  System.err.println(ioe.getLocalizedMessage());
} finally {
  channel.disconnect();

代码示例来源:origin: org.apache.ant/ant

/**
 * A test method.
 * @param args not used
 */
public static void main(String[] args) {
  try {
    Hashtable<String, String> hash = new Hashtable<>();
    hash.put("VERSION", "1.0.3");
    hash.put("b", "ffff");
    System.out.println(KeySubst.replace("$f ${VERSION} f ${b} jj $",
                      hash));
  } catch (Exception e) {
    e.printStackTrace(); //NOSONAR
  }
}

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

final String password = "yourpassword";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
  message.setFrom(new InternetAddress("your_user_name@gmail.com"));
  message.setRecipients(Message.RecipientType.TO,
    InternetAddress.parse("to_email_address@domain.com"));
  System.out.println("Done");

代码示例来源:origin: robovm/robovm

private <K> void selectProperties(Hashtable<K, Object> selectProperties, final boolean isStringOnly) {
  if (defaults != null) {
    defaults.selectProperties(selectProperties, isStringOnly);
  }
  Enumeration<Object> keys = keys();
  while (keys.hasMoreElements()) {
    @SuppressWarnings("unchecked")
    K key = (K) keys.nextElement();
    if (isStringOnly && !(key instanceof String)) {
      // Only select property with string key and value
      continue;
    }
    Object value = get(key);
    selectProperties.put(key, value);
  }
}

代码示例来源:origin: Sable/soot

private static int getNodeOrder(Hashtable<Object, Integer> nodeindex, Object node) {
 if (node == null) {
  System.out.println("----node is null-----");
  return 0;
  // System.exit(1); // RLH
 }
 // System.out.println("node is: "+node);
 Integer index = nodeindex.get(node);
 if (index == null) {
  index = new Integer(nodecount++);
  nodeindex.put(node, index);
 }
 // System.out.println("order is:"+index.intValue());
 return index.intValue();
}

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

String from = "user name";
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", "asdfgh");
props.put("mail.smtp.port", "587"); // 587 is the port number of yahoo mail
props.put("mail.smtp.auth", "true");
message.setFrom(new InternetAddress(from));
  i++;
System.out.println(Message.RecipientType.TO);
i = 0;
while (to_address[i] != null) {

代码示例来源:origin: marytts/marytts

this.modelTable.put(keyString, valueString);
          System.out.println("ERROR: The " + i + "th entry contains wrong number of subElements !!");
    System.out.println("Document is not wellformed. Top-level element should be <entries>.");
  System.out.println("Can't find file '" + modelPath + "'.");
} catch (ParserConfigurationException e) {
  System.out.println("Parser Configuration exception (Use trace mode for details)");

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

this.password = password;   
Properties props = new Properties();   
props.setProperty("mail.transport.protocol", "smtp");   
props.setProperty("mail.host", mailhost);   
props.put("mail.smtp.auth", "true");   
props.put("mail.smtp.port", "465");   
props.put("mail.smtp.socketFactory.port", "465");   
props.put("mail.smtp.socketFactory.class",   
    "javax.net.ssl.SSLSocketFactory");   
props.put("mail.smtp.socketFactory.fallback", "false");   
props.setProperty("mail.smtp.quitwait", "false");   
MimeMessage message = new MimeMessage(session);   
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));   
message.setSender(new InternetAddress(sender));   
message.setSubject(subject);   
message.setDataHandler(handler);   
  message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients));   
else  
  message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));   
Transport.send(message);   
}catch(Exception e){

代码示例来源:origin: robovm/robovm

ENCODINGS_FILE);
Properties props = new Properties();
if (is != null) {
  props.load(is);
for (int i = 0; i < totalEntries; ++i)
  String javaName = (String) keys.nextElement();
  String val = props.getProperty(javaName);
  int len = lengthOfMimeNames(val);
      EncodingInfo ei = new EncodingInfo(mimeName, javaName, highChar);
      encodingInfo_list.add(ei);
      _encodingTableKeyMime.put(mimeName.toUpperCase(), ei);
      if (first)
        _encodingTableKeyJava.put(javaName.toUpperCase(), ei);

代码示例来源:origin: robovm/robovm

private void addCDATAElement(String uri, String localName) 
{
  if (m_CdataElems == null) {
    m_CdataElems = new java.util.Hashtable();
  }
  
  java.util.Hashtable h = (java.util.Hashtable) m_CdataElems.get(localName);
  if (h == null) {
    h = new java.util.Hashtable();
    m_CdataElems.put(localName,h);
  }
  h.put(uri,uri);
  
}

代码示例来源:origin: spotbugs/spotbugs

public void hashtablesCantContainNull(Hashtable h) {
    h.put("a", null);
    h.put(null, "a");
    h.get(null);
    h.contains(null);
    h.containsKey(null);
    h.containsValue(null);
    h.remove(null);

  }
}

代码示例来源:origin: javax.servlet/servlet-api

throw new IllegalArgumentException();
Hashtable ht = new Hashtable();
StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(s, "&");
  if (ht.containsKey(key)) {
  String oldVals[] = (String []) ht.get(key);
  valArray = new String[oldVals.length + 1];
  for (int i = 0; i < oldVals.length; i++) 
  valArray[0] = val;
  ht.put(key, valArray);

代码示例来源:origin: xalan/xalan

/**
 * This method starts at a given node, traverses all namespace mappings,
 * and assembles a list of all prefixes that (for the given node) maps
 * to _ANY_ namespace URI. Used by literal result elements to determine
 */
public Enumeration getNamespaceScope(SyntaxTreeNode node) {
Hashtable all = new Hashtable();

while (node != null) {
  Hashtable mapping = node.getPrefixMapping();
  if (mapping != null) {
  Enumeration prefixes = mapping.keys();
  while (prefixes.hasMoreElements()) {
    String prefix = (String)prefixes.nextElement();
    if (!all.containsKey(prefix)) {
    all.put(prefix, mapping.get(prefix));
    }
  }
  }
  node = node.getParent();
}
return(all.keys());
}

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

Channel channel = null;
ChannelSftp channelSftp = null;
System.out.println("preparing the host information for sftp.");
try {
  JSch jsch = new JSch();
  session = jsch.getSession(SFTPUSER, SFTPHOST, SFTPPORT);
  session.setPassword(SFTPPASS);
  java.util.Properties config = new java.util.Properties();
  config.put("StrictHostKeyChecking", "no");
  session.setConfig(config);
  session.connect();
  System.out.println("Host connected.");
  channel = session.openChannel("sftp");
  channel.connect();
  System.out.println("sftp channel opened and connected.");
  channelSftp = (ChannelSftp) channel;
  channelSftp.cd(SFTPWORKINGDIR);

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

System.out.println("Début du test Active Directory");
Hashtable<String, String> ldapEnv = new Hashtable<String, String>(11);
ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
ldapEnv.put(Context.PROVIDER_URL,  "ldap://dom.fr:389");
ldapEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
ldapEnv.put(Context.SECURITY_PRINCIPAL, "cn=jean paul blanc,ou=MonOu,dc=dom,dc=fr");
ldapEnv.put(Context.SECURITY_CREDENTIALS, "pwd");
 System.out.println(">>>" + sr.getName());
 Attributes attrs = sr.getAttributes();
 System.out.println(">>>>>>" + attrs.get("samAccountName"));

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

final String password = "your.password";
Properties props = new Properties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
  message.setFrom(new InternetAddress("from.mail.id@gmail.com"));
  message.setRecipients(Message.RecipientType.TO,
      InternetAddress.parse("to.mail.id@gmail.com"));
  System.out.println("Sending");
  System.out.println("Done");

相关文章