本文整理汇总了Java中java.util.ArrayList.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayList.toArray方法的具体用法?Java ArrayList.toArray怎么用?Java ArrayList.toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayList
的用法示例。
在下文中一共展示了ArrayList.toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValves
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Return the set of Valves in the pipeline associated with this
* Container, including the basic Valve (if any). If there are no
* such Valves, a zero-length array is returned.
*/
public Valve[] getValves() {
ArrayList valveList = new ArrayList();
Valve current = first;
if (current == null) {
current = basic;
}
while (current != null) {
valveList.add(current);
current = current.getNext();
}
return ((Valve[]) valveList.toArray(new Valve[0]));
}
示例2: decodeWaypointConstraint
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Decodes a waypoint constraint.
*
* @return waypoint constraint object.
*/
private Constraint decodeWaypointConstraint() {
JsonNode waypoints = nullIsIllegal(json.get(ConstraintCodec.WAYPOINTS),
ConstraintCodec.WAYPOINTS + ConstraintCodec.MISSING_MEMBER_MESSAGE);
if (waypoints.size() < 1) {
throw new IllegalArgumentException(
"obstacles array in obstacles constraint must have at least one value");
}
ArrayList<DeviceId> waypointEntries = new ArrayList<>(waypoints.size());
IntStream.range(0, waypoints.size())
.forEach(index ->
waypointEntries.add(DeviceId.deviceId(waypoints.get(index).asText())));
return new WaypointConstraint(
waypointEntries.toArray(new DeviceId[waypoints.size()]));
}
示例3: getResourceLinks
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Return the MBean Names of all the defined resource link references for
* this application.
*/
public String[] getResourceLinks() {
ContextResourceLink[] resourceLinks =
((NamingResources)this.resource).findResourceLinks();
ArrayList results = new ArrayList();
for (int i = 0; i < resourceLinks.length; i++) {
try {
ObjectName oname =
MBeanUtils.createObjectName(managed.getDomain(), resourceLinks[i]);
results.add(oname.toString());
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException
("Cannot create object name for resource " + resourceLinks[i]);
}
}
return ((String[]) results.toArray(new String[results.size()]));
}
示例4: getSign
import java.util.ArrayList; //导入方法依赖的package包/类
public static String getSign(Map<String,Object> map, String key){
ArrayList<String> list = new ArrayList<String>();
for(Map.Entry<String,Object> entry:map.entrySet()){
if(!"".equals(entry.getValue())){
list.add(entry.getKey() + "=" + entry.getValue() + "&");
}
}
int size = list.size();
String [] arrayToSort = list.toArray(new String[size]);
Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < size; i ++) {
sb.append(arrayToSort[i]);
}
String result = sb.toString();
result += "key=" + key;
_log.debug("Sign Before MD5:" + result);
result = md5(result, encodingCharset).toUpperCase();
_log.debug("Sign Result:" + result);
return result;
}
示例5: getChildren
import java.util.ArrayList; //导入方法依赖的package包/类
public XppDom[] getChildren(final String name) {
if (null == childList) {
return new XppDom[0];
} else {
final ArrayList<XppDom> children = new ArrayList<XppDom>();
final int size = childList.size();
for (int i = 0; i < size; i++) {
final XppDom configuration = childList.get(i);
if (name.equals(configuration.getName())) {
children.add(configuration);
}
}
return children.toArray(new XppDom[0]);
}
}
示例6: readSpecFile
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Read and parse a Unicode data file.
*
* @param file a file specifying the Unicode data file to be read
* @return an array of UnicodeSpec objects, one for each line of the
* Unicode data file that could be successfully parsed as
* specifying Unicode character attributes
*/
public static UnicodeSpec[] readSpecFile(File file, int plane) throws FileNotFoundException {
ArrayList<UnicodeSpec> list = new ArrayList<>(3000);
UnicodeSpec[] result = null;
int count = 0;
BufferedReader f = new BufferedReader(new FileReader(file));
String line = null;
loop:
while(true) {
try {
line = f.readLine();
}
catch (IOException e) {
break loop;
}
if (line == null) break loop;
UnicodeSpec item = parse(line.trim());
int specPlane = item.getCodePoint() >>> 16;
if (specPlane < plane) continue;
if (specPlane > plane) break;
if (item != null) {
list.add(item);
}
}
result = new UnicodeSpec[list.size()];
list.toArray(result);
return result;
}
示例7: resolveAnnotationValue
import java.util.ArrayList; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected static <T> T resolveAnnotationValue(Class<T> expectedType, AnnotationValue value) {
if (value == null) {
return null;
}
if (expectedType.isArray()) {
ArrayList<Object> result = new ArrayList<>();
List<AnnotationValue> l = (List<AnnotationValue>) value.getValue();
for (AnnotationValue el : l) {
result.add(resolveAnnotationValue(expectedType.getComponentType(), el));
}
return (T) result.toArray((Object[]) Array.newInstance(expectedType.getComponentType(), result.size()));
}
Object unboxedValue = value.getValue();
if (unboxedValue != null) {
if (expectedType == TypeMirror.class && unboxedValue instanceof String) {
/*
* Happens if type is invalid when using the ECJ compiler. The ECJ does not match
* AP-API specification here.
*/
return null;
}
if (!expectedType.isAssignableFrom(unboxedValue.getClass())) {
throw new ClassCastException(unboxedValue.getClass().getName() + " not assignable from " + expectedType.getName());
}
}
return (T) unboxedValue;
}
示例8: findApplicationListeners
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Return the set of application listener class names configured
* for this application.
*/
@Override
public String[] findApplicationListeners() {
ArrayList<String> list =
new ArrayList<String>(applicationListeners.length);
for (ApplicationListener applicationListener: applicationListeners) {
list.add(applicationListener.getClassName());
}
return list.toArray(new String[list.size()]);
}
示例9: generateTestConfigs
import java.util.ArrayList; //导入方法依赖的package包/类
protected TestConfig[] generateTestConfigs(int numberOfTests, TestDoc[] testDocs, TestFieldSetting[] fieldSettings) {
ArrayList<TestConfig> configs = new ArrayList<>();
for (int i = 0; i < numberOfTests; i++) {
ArrayList<String> selectedFields = null;
if (randomBoolean()) {
// used field selection
selectedFields = new ArrayList<>();
if (randomBoolean()) {
selectedFields.add("Doesnt_exist"); // this will be ignored.
}
for (TestFieldSetting field : fieldSettings)
if (randomBoolean()) {
selectedFields.add(field.name);
}
if (selectedFields.size() == 0) {
selectedFields = null; // 0 length set is not supported.
}
}
TestConfig config = new TestConfig(testDocs[randomInt(testDocs.length - 1)], selectedFields == null ? null
: selectedFields.toArray(new String[]{}), randomBoolean(), randomBoolean(), randomBoolean());
configs.add(config);
}
// always adds a test that fails
configs.add(new TestConfig(new TestDoc("doesnt_exist", new TestFieldSetting[]{}, new String[]{}).index("doesn't_exist").alias("doesn't_exist"),
new String[]{"doesnt_exist"}, true, true, true).expectedException(org.elasticsearch.index.IndexNotFoundException.class));
refresh();
return configs.toArray(new TestConfig[configs.size()]);
}
示例10: getByCommand
import java.util.ArrayList; //导入方法依赖的package包/类
public static InetAddress[] getByCommand() {
try {
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(Runtime.getRuntime
().exec("getprop").getInputStream()));
ArrayList<InetAddress> servers = new ArrayList(5);
while (true) {
String line = lnr.readLine();
if (line == null) {
break;
}
int split = line.indexOf("]: [");
if (split != -1) {
String property = line.substring(1, split);
String value = line.substring(split + 4, line.length() - 1);
if (property.endsWith(".dns") || property.endsWith(".dns1") || property
.endsWith(".dns2") || property.endsWith(".dns3") || property.endsWith
(".dns4")) {
InetAddress ip = InetAddress.getByName(value);
if (ip != null) {
value = ip.getHostAddress();
if (!(value == null || value.length() == 0)) {
servers.add(ip);
}
}
}
}
}
if (servers.size() > 0) {
return (InetAddress[]) servers.toArray(new InetAddress[servers.size()]);
}
} catch (IOException e) {
Logger.getLogger("AndroidDnsServer").log(Level.WARNING, "Exception in findDNSByExec",
e);
}
return null;
}
示例11: getValues
import java.util.ArrayList; //导入方法依赖的package包/类
String[] getValues() {
ArrayList valueList = new ArrayList();
FormControl[] controls = getControls();
for (int i = 0; i < controls.length; i++) {
valueList.addAll( Arrays.asList( controls[i].getValues() ) );
}
return (String[]) valueList.toArray( new String[ valueList.size() ] );
}
示例12: initializeTableA
import java.util.ArrayList; //导入方法依赖的package包/类
public static VoltTable initializeTableA() {
ArrayList<VoltTable.ColumnInfo> columns = new ArrayList<VoltTable.ColumnInfo>();
String prefix = "A";
columns.add(new VoltTable.ColumnInfo(prefix + "_ID", VoltType.BIGINT));
addStringColumns(columns, 20, prefix);
addIntegerColumns(columns, 20, prefix);
VoltTable.ColumnInfo cols[] = new VoltTable.ColumnInfo[columns.size()];
return (new VoltTable(columns.toArray(cols)));
}
示例13: splitOnTokens
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Splits a string into a number of tokens.
* The text is split by '?' and '*'.
* Where multiple '*' occur consecutively they are collapsed into a single '*'.
*
* @param text the text to split
* @return the array of tokens, never null
*/
static String[] splitOnTokens(String text) {
// used by wildcardMatch
// package level so a unit test may run on this
if (text.indexOf('?') == -1 && text.indexOf('*') == -1) {
return new String[] { text };
}
char[] array = text.toCharArray();
ArrayList<String> list = new ArrayList<String>();
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < array.length; i++) {
if (array[i] == '?' || array[i] == '*') {
if (buffer.length() != 0) {
list.add(buffer.toString());
buffer.setLength(0);
}
if (array[i] == '?') {
list.add("?");
} else if (list.size() == 0 ||
(i > 0 && list.get(list.size() - 1).equals("*") == false)) {
list.add("*");
}
} else {
buffer.append(array[i]);
}
}
if (buffer.length() != 0) {
list.add(buffer.toString());
}
return list.toArray( new String[ list.size() ] );
}
示例14: setOriginalParser
import java.util.ArrayList; //导入方法依赖的package包/类
public void setOriginalParser(ArrayList<String> vargs) throws Exception
{
String[] args = new String[vargs.size()];
args = vargs.toArray(args);
this.m_origianlParser = ArgumentsParser.load(args,
ArgumentsParser.PARAM_CATALOG
);
catalog = this.m_origianlParser.catalog;
}
示例15: computeLineText
import java.util.ArrayList; //导入方法依赖的package包/类
private void computeLineText(FontMetrics fm) {
String text = exprData.text;
int[] badness = exprData.badness;
if (fm.stringWidth(text) <= width) {
lineText = new String[] { text };
return;
}
int startPos = 0;
ArrayList<String> lines = new ArrayList<String>();
while (startPos < text.length()) {
int stopPos = startPos + 1;
String bestLine = text.substring(startPos, stopPos);
if (stopPos >= text.length()) {
lines.add(bestLine);
break;
}
int bestStopPos = stopPos;
int lineWidth = fm.stringWidth(bestLine);
int bestBadness = badness[stopPos] + (width - lineWidth) * BADNESS_PER_PIXEL;
while (stopPos < text.length()) {
++stopPos;
String line = text.substring(startPos, stopPos);
lineWidth = fm.stringWidth(line);
if (lineWidth > width)
break;
int lineBadness = badness[stopPos] + (width - lineWidth) * BADNESS_PER_PIXEL;
if (lineBadness < bestBadness) {
bestBadness = lineBadness;
bestStopPos = stopPos;
bestLine = line;
}
}
lines.add(bestLine);
startPos = bestStopPos;
}
lineText = lines.toArray(new String[lines.size()]);
}