java.util.Vector类的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(210)

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

Vector介绍

[英]Vector is an implementation of List, backed by an array and synchronized. All optional operations including adding, removing, and replacing elements are supported.

All elements are permitted, including null.

This class is equivalent to ArrayList with synchronized operations. This has a performance cost, and the synchronization is not necessarily meaningful to your application: synchronizing each call to get, for example, is not equivalent to synchronizing on the list and iterating over it (which is probably what you intended). If you do need very highly concurrent access, you should also consider java.util.concurrent.CopyOnWriteArrayList.
[中]Vector是List的一个实现,由一个数组支持并同步。支持所有可选操作,包括添加、删除和替换图元。
所有元素都是允许的,包括null。
此类相当于具有同步操作的ArrayList。这会带来性能成本,而且同步对应用程序不一定有意义:例如,同步每个要获取的调用并不等同于同步列表并对其进行迭代(这可能是您想要的)。如果你需要非常高的并发访问,你也应该考虑java。util。同时发生的CopyOnWriteArrayList。

代码示例

代码示例来源:origin: alibaba/druid

public Enumeration<ColumnGroup> getColumnGroups(TableColumn col) {
  if (columnGroups == null) {
    return null;
  }
  Enumeration<ColumnGroup> enum1 = columnGroups.elements();
  while (enum1.hasMoreElements()) {
    ColumnGroup cGroup = (ColumnGroup) enum1.nextElement();
    Vector<ColumnGroup> v_ret = cGroup.getColumnGroups(col, new Vector<ColumnGroup>());
    if (v_ret != null) {
      return v_ret.elements();
    }
  }
  return null;
}

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

public SortedKeyEnumeration(Hashtable ht) {
 Enumeration f = ht.keys();
 Vector keys = new Vector(ht.size());
 for (int i, last = 0; f.hasMoreElements(); ++last) {
  String key = (String) f.nextElement();
  for (i = 0; i < last; ++i) {
   String s = (String) keys.get(i);
   if (key.compareTo(s) <= 0) break;
  }
  keys.add(i, key);
 }
 e = keys.elements();
}

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

ZipEntryRO[] getEntriesAt(String path) {
  Vector<ZipEntryRO> zev = new Vector<ZipEntryRO>();
  Collection<ZipEntryRO> values = mHashMap.values();
  if (null == path)
    path = "";
  int length = path.length();
  for (ZipEntryRO ze : values) {
    if (ze.mFileName.startsWith(path)) {
      if (-1 == ze.mFileName.indexOf('/', length)) {
        zev.add(ze);
      }
    }
  }
  ZipEntryRO[] entries = new ZipEntryRO[zev.size()];
  return zev.toArray(entries);
}

代码示例来源:origin: alibaba/druid

public ColumnGroup[] getColumnGroups() {
  ColumnGroup[] retg = null;
  if (columnGroups.size() > 0) {
    retg = new ColumnGroup[columnGroups.size()];
    columnGroups.copyInto(retg);
  }
  return retg;
}

代码示例来源:origin: alibaba/druid

public void addColumnGroup(ColumnGroup g) {
  if (columnGroups == null) {
    columnGroups = new Vector<ColumnGroup>();
  }
  columnGroups.addElement(g);
}

代码示例来源:origin: jenkinsci/jenkins

public String[] getStatuses() {
  synchronized (statuses) {
    return statuses.toArray(new String[statuses.size()]);
  }
}

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

name = key.substring(dotIdx+1);
  Vector filterOpts = (Vector) filters.get(filterKey);
  if (filterOpts == null) {
   filterOpts = new Vector();
   filters.put(filterKey, filterOpts);
   filterOpts.add(new NameValue(name, value));
while (g.hasMoreElements()) {
 String key = (String) g.nextElement();
 String clazz = props.getProperty(key);
 if (clazz != null) {
  LogLog.debug("Filter key: ["+key+"] class: ["+props.getProperty(key) +"] props: "+filters.get(key));
  Filter filter = (Filter) OptionConverter.instantiateByClassName(clazz, Filter.class, null);
  if (filter != null) {
   PropertySetter propSetter = new PropertySetter(filter);
   Vector v = (Vector)filters.get(key);
   Enumeration filterProps = v.elements();
   while (filterProps.hasMoreElements()) {
    NameValue kv = (NameValue)filterProps.nextElement();

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

if ((null == v) || (v.size() < 1))
 return false;
for (int i = 0; i < v.size(); i++)
 Hashtable subhash = (Hashtable) v.elementAt(i);
 for (Enumeration keys = subhash.keys(); 
    keys.hasMoreElements();
  Object key = keys.nextElement();
  try
   node.setAttribute("name", keyStr.substring(0, keyStr.indexOf("-")));
   node.setAttribute("desc", keyStr.substring(keyStr.indexOf("-") + 1));
   node.appendChild(factory.createTextNode((String)subhash.get(keyStr)));
   container.appendChild(node);

代码示例来源:origin: alibaba/druid

public void setColumnMargin(int margin) {
  this.margin = margin;
  Enumeration<Object> enumeration = vector.elements();
  while (enumeration.hasMoreElements()) {
    Object obj = enumeration.nextElement();
    if (obj instanceof ColumnGroup) {
      ((ColumnGroup) obj).setColumnMargin(margin);
    }
  }
}

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

public Enumeration getCurrentLoggers() {
  Vector<Logger> loggers = new Vector<Logger>(ht.size());
  Enumeration elems = ht.elements();
  while (elems.hasMoreElements()) {
    Object o = elems.nextElement();
    if (o instanceof Logger) {
      Logger logger = (Logger)o;
      loggers.addElement(logger);
    }
  }
  return loggers.elements();
}

代码示例来源:origin: org.ow2.joram/joram-mom-core

public void setProperties(Properties properties) {
 if (properties != null) {
  elements.clear();
  Enumeration<Object> e = properties.keys();
  while (e.hasMoreElements()) {
   String name = (String) e.nextElement();
   String attributes = ConversionHelper.toString(properties.get(name));
   elements.add(new MonitoringElement(name, attributes));
  }
 }
}

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

v = new Vector(); 
 Enumeration enumeration = ht.keys();
 while(enumeration.hasMoreElements() && (misses <= 4)) {
Thread t = (Thread) enumeration.nextElement();
if(t.isAlive()) {
 misses++;
} else {
 misses = 0;
 v.addElement(t);
int size = v.size();
for(int i = 0; i < size; i++) {
 Thread t = (Thread) v.elementAt(i);
 LogLog.debug("Lazy NDC removal for thread [" + t.getName() + "] ("+ 
    ht.size() + ").");
 ht.remove(t);

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

/**
 * Return an array containing the names of all currently defined
 * configuration attributes.  If there are no such attributes, a zero
 * length array is returned.
 */
public String[] getAttributeNames() {
  Vector names = new Vector();
  Enumeration keys = attributes.keys();
  while (keys.hasMoreElements()) {
    names.addElement((String) keys.nextElement());
  }
  String results[] = new String[names.size()];
  for (int i = 0; i < results.length; i++) {
    results[i] = (String) names.elementAt(i);
  }
  return (results);
}

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

public static void main(String[] args) throws Exception {
 SortedProperties sp = new SortedProperties();
 sp.put("B", "value B");
 sp.put("C", "value C");
 sp.put("A", "value A");
 sp.put("D", "value D");
 FileOutputStream fos = new FileOutputStream("sp.props");
 sp.store(fos, "sorted props");
public Enumeration keys() {
  Enumeration keysEnum = super.keys();
  Vector<String> keyList = new Vector<String>();
  while(keysEnum.hasMoreElements()){
   keyList.add((String)keysEnum.nextElement());
  return keyList.elements();

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

Enumeration names = _properties.propertyNames();
while (names.hasMoreElements()) {
  String name  = (String) names.nextElement();
  String value = (String) _properties.get(name);
            uriAndLocalNames = new Vector();
          uriAndLocalNames.addElement(uri);
          uriAndLocalNames.addElement(localName);

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

private Target onStartTarget(final Attributes attrs, String tagName, String ns) {
  final Target target = new Target();
  target.setProject(project);
  target.setLocation(new Location(antXmlContext.getLocator()));
  try {
    antTargetHandler.onStartElement(ns, tagName, tagName, attrs, antXmlContext);
    final Target newTarget = getProject().getTargets().get(attrs.getValue("name"));
    // execute dependencies (if any)
    final Vector<Target> targets = new Vector<Target>();
    for (final Enumeration<String> deps = newTarget.getDependencies(); deps.hasMoreElements();) {
      final String targetName = deps.nextElement();
      targets.add(project.getTargets().get(targetName));
    }
    getProject().executeSortedTargets(targets);
    antXmlContext.setCurrentTarget(newTarget);
    return newTarget;
  }
  catch (final SAXParseException e) {
    log.log(Level.SEVERE, "Caught: " + e, e);
  }
  return null;
}

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

public java.sql.ResultSet getTableTypes() throws SQLException
{
  String types[] = new String[tableTypeClauses.size()];
  Enumeration e = tableTypeClauses.keys();
  int i = 0;
  while (e.hasMoreElements())
  {
    types[i++] = (String)e.nextElement();
  }
  sortStringArray(types);
  Field f[] = new Field[1];
  Vector v = new Vector();
  f[0] = new Field("TABLE_TYPE", Oid.VARCHAR);
  for (i = 0; i < types.length; i++)
  {
    byte[][] tuple = new byte[1][];
    tuple[0] = connection.encodeString(types[i]);
    v.addElement(tuple);
  }
  return (ResultSet) ((BaseStatement)createMetaDataStatement()).createDriverResultSet(f, v);
}

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

_templates = quicksort(_templates, 0, _templates.size() - 1);
final Enumeration templates = _templates.elements();
while (templates.hasMoreElements()) {
  final Template template = (Template)templates.nextElement();
  _namedTemplates.put(template, this);

代码示例来源:origin: org.codehaus.plexus/plexus-ftpd

/**
 * Get all property key names.
 */
public List getAllKeys() {
  Vector keys = new Vector();
  for(Enumeration en = propertyNames(); en.hasMoreElements(); ) {
    keys.add(en.nextElement().toString());
  }
  return keys;
}

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

public String[] toStringArray() {
 int len = v.size();
 String[] sa = new String[len];
 for(int i = 0; i < len; i++) {
  sa[i] = (String) v.elementAt(i);
 }
 return sa;
}

相关文章

微信公众号

最新文章

更多