本文整理了Java中java.util.Set.toArray()
方法的一些代码示例,展示了Set.toArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Set.toArray()
方法的具体详情如下:
包路径:java.util.Set
类名称:Set
方法名:toArray
[英]Returns an array containing all elements contained in this set.
[中]返回包含此集合中包含的所有元素的数组。
代码示例来源:origin: spring-projects/spring-framework
public String[] getAttributeNames() {
return this.attributes.keySet().toArray(new String[0]);
}
代码示例来源:origin: libgdx/libgdx
public Class[] getInterfaces() {
return interfaces.toArray(new Class[this.interfaces.size()]);
}
代码示例来源:origin: spring-projects/spring-framework
public static Method[] getPropertyMethods(PropertyDescriptor[] properties, boolean read, boolean write) {
Set methods = new HashSet();
for (int i = 0; i < properties.length; i++) {
PropertyDescriptor pd = properties[i];
if (read) {
methods.add(pd.getReadMethod());
}
if (write) {
methods.add(pd.getWriteMethod());
}
}
methods.remove(null);
return (Method[]) methods.toArray(new Method[methods.size()]);
}
代码示例来源:origin: google/j2objc
public AddPropertyTransformer(Map props) {
int size = props.size();
names = (String[])props.keySet().toArray(new String[size]);
types = new Type[size];
for (int i = 0; i < size; i++) {
types[i] = (Type)props.get(names[i]);
}
}
代码示例来源:origin: google/guava
@Override
TypeVariable<?> captureAsTypeVariable(Type[] upperBounds) {
Set<Type> combined = new LinkedHashSet<>(asList(upperBounds));
// Since this is an artifically generated type variable, we don't bother checking
// subtyping between declared type bound and actual type bound. So it's possible that we
// may generate something like <capture#1-of ? extends Foo&SubFoo>.
// Checking subtype between declared and actual type bounds
// adds recursive isSubtypeOf() call and feels complicated.
// There is no contract one way or another as long as isSubtypeOf() works as expected.
combined.addAll(asList(typeParam.getBounds()));
if (combined.size() > 1) { // Object is implicit and only useful if it's the only bound.
combined.remove(Object.class);
}
return super.captureAsTypeVariable(combined.toArray(new Type[0]));
}
};
代码示例来源:origin: robolectric/robolectric
@Implementation
protected @Nullable String[] getPackagesForUid(int uid) {
String[] packageNames = packagesForUid.get(uid);
if (packageNames != null) {
return packageNames;
}
Set<String> results = new HashSet<>();
for (PackageInfo packageInfo : packageInfos.values()) {
if (packageInfo.applicationInfo != null && packageInfo.applicationInfo.uid == uid) {
results.add(packageInfo.packageName);
}
}
return results.isEmpty() ? null : results.toArray(new String[results.size()]);
}
代码示例来源:origin: google/guava
Set<K> keySet = map.keySet();
Collection<V> valueCollection = map.values();
Set<Entry<K, V>> entrySet = map.entrySet();
V value = map.get(key);
expectedKeySetHash += key != null ? key.hashCode() : 0;
assertTrue(map.containsKey(key));
assertEquals(map.size(), valueCollection.size());
assertEquals(valueCollection.size() == 0, valueCollection.isEmpty());
assertEquals(!valueCollection.isEmpty(), valueCollection.iterator().hasNext());
Object[] entrySetToArray1 = entrySet.toArray();
assertEquals(map.size(), entrySetToArray1.length);
assertTrue(Arrays.asList(entrySetToArray1).containsAll(entrySet));
Entry<?, ?>[] entrySetToArray2 = new Entry<?, ?>[map.size() + 2];
entrySetToArray2[map.size()] = mapEntry("foo", 1);
assertSame(entrySetToArray2, entrySet.toArray(entrySetToArray2));
assertNull(entrySetToArray2[map.size()]);
assertTrue(Arrays.asList(entrySetToArray2).containsAll(entrySet));
assertEquals(map.size(), valuesToArray1.length);
assertTrue(Arrays.asList(valuesToArray1).containsAll(valueCollection));
Object[] valuesToArray2 = new Object[map.size() + 2];
代码示例来源:origin: robolectric/robolectric
@Override
public int getAvailableRestoreSets(IRestoreObserver observer, IBackupManagerMonitor monitor)
throws RemoteException {
post(
() -> {
Set<Long> restoreTokens = serviceState.restoreData.keySet();
Set<RestoreSet> restoreSets = new HashSet<>();
for (long token : restoreTokens) {
restoreSets.add(new RestoreSet("RestoreSet-" + token, "device", token));
}
observer.restoreSetsAvailable(restoreSets.toArray(new RestoreSet[restoreSets.size()]));
});
return BackupManager.SUCCESS;
}
代码示例来源:origin: apache/flink
/**
* Returns the names of all registered column families.
*
* @return The names of all registered column families.
*/
String[] getFamilyNames() {
return this.familyMap.keySet().toArray(new String[this.familyMap.size()]);
}
代码示例来源:origin: jfinal/jfinal
/**
* Return attribute names of this model.
*/
public String[] _getAttrNames() {
Set<String> attrNameSet = attrs.keySet();
return attrNameSet.toArray(new String[attrNameSet.size()]);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
public void print(){
System.out.println("-----------------");
Set<Integer> keys = objs.keySet();
Integer[] keysArr = keys.toArray(new Integer[0]);
Arrays.sort(keysArr);
for (int i = 0; i < keysArr.length; i++){
System.out.println(keysArr[i]+" => "+objs.get(keysArr[i]).hashCode());
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/**
* dump the {@code <x,y>} pairs it computed found
*/
public void dumpMemory() {
Double[] keys = memory.keySet().toArray(new Double[memory.keySet().size()]);
Arrays.sort(keys);
for (Double key : keys) {
log.info(key + "\t" + memory.get(key));
}
}
代码示例来源:origin: ben-manes/caffeine
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
public void keySetToArray(Map<Integer, Integer> map, CacheContext context) {
int length = context.original().size();
Integer[] ints = map.keySet().toArray(new Integer[length]);
assertThat(ints.length, is(length));
assertThat(Arrays.asList(ints).containsAll(context.original().keySet()), is(true));
Object[] array = map.keySet().toArray();
assertThat(array.length, is(length));
assertThat(Arrays.asList(array).containsAll(context.original().keySet()), is(true));
}
代码示例来源:origin: google/guava
/**
* Returns a new proxy for {@code interfaceType}. Proxies of the same interface are equal to each
* other if the {@link DummyProxy} instance that created the proxies are equal.
*/
final <T> T newProxy(TypeToken<T> interfaceType) {
Set<Class<?>> interfaceClasses = Sets.newLinkedHashSet();
interfaceClasses.addAll(interfaceType.getTypes().interfaces().rawTypes());
// Make the proxy serializable to work with SerializableTester
interfaceClasses.add(Serializable.class);
Object dummy =
Proxy.newProxyInstance(
interfaceClasses.iterator().next().getClassLoader(),
interfaceClasses.toArray(new Class<?>[interfaceClasses.size()]),
new DummyHandler(interfaceType));
@SuppressWarnings("unchecked") // interfaceType is T
T result = (T) dummy;
return result;
}
代码示例来源:origin: ctripcorp/apollo
@Override
public String[] getPropertyNames() {
Set<String> propertyNames = this.source.getPropertyNames();
if (propertyNames.isEmpty()) {
return EMPTY_ARRAY;
}
return propertyNames.toArray(new String[propertyNames.size()]);
}
代码示例来源:origin: javax.activation/activation
/**
* Return all the MIME types known to this mailcap file.
*/
public String[] getMimeTypes() {
Set types = new HashSet(type_hash.keySet());
types.addAll(fallback_hash.keySet());
types.addAll(native_commands.keySet());
String[] mts = new String[types.size()];
mts = (String[])types.toArray(mts);
return mts;
}
代码示例来源:origin: apache/nifi
private static URL[] combineURLs(final Set<URL> instanceUrls, final Set<URL> additionalResourceUrls) {
final Set<URL> allUrls = new LinkedHashSet<>();
if (instanceUrls != null) {
allUrls.addAll(instanceUrls);
}
if (additionalResourceUrls != null) {
allUrls.addAll(additionalResourceUrls);
}
return allUrls.toArray(new URL[allUrls.size()]);
}
代码示例来源:origin: stackoverflow.com
Set<Integer> s1 = new HashSet<Integer>(Arrays.asList(array1));
Set<Integer> s2 = new HashSet<Integer>(Arrays.asList(array2));
s1.retainAll(s2);
Integer[] result = s1.toArray(new Integer[s1.size()]);
代码示例来源:origin: spring-projects/spring-security-oauth
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) {
Map<String, String> params = tokenRequest.getRequestParameters();
String username = params.containsKey("username") ? params.get("username") : "guest";
List<GrantedAuthority> authorities = params.containsKey("authorities") ? AuthorityUtils
.createAuthorityList(OAuth2Utils.parseParameterList(params.get("authorities")).toArray(new String[0]))
: AuthorityUtils.NO_AUTHORITIES;
Authentication user = new UsernamePasswordAuthenticationToken(username, "N/A", authorities);
OAuth2Authentication authentication = new OAuth2Authentication(tokenRequest.createOAuth2Request(client), user);
return authentication;
}
}
代码示例来源:origin: ben-manes/caffeine
@CheckNoWriter @CheckNoStats
@Test(dataProvider = "caches")
@CacheSpec(removalListener = { Listener.DEFAULT, Listener.REJECTING })
public void entriesToArray(Map<Integer, Integer> map, CacheContext context) {
int length = context.original().size();
Object[] ints = map.entrySet().toArray(new Object[length]);
assertThat(ints.length, is(length));
assertThat(Arrays.asList(ints).containsAll(context.original().entrySet()), is(true));
Object[] array = map.entrySet().toArray();
assertThat(array.length, is(length));
assertThat(Arrays.asList(array).containsAll(context.original().entrySet()), is(true));
}
内容来源于网络,如有侵权,请联系作者删除!