gpt4 book ai didi

Java - 返回 2 个值(字符串数组)

转载 作者:行者123 更新时间:2023-12-02 08:07:28 25 4
gpt4 key购买 nike

我有这个java代码,我想返回2个值,然后在main()或其他函数中使用它们。请提供一些帮助。发送:

import java.net.*;
import java.io.*;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

public class URLReader {

public String[] functie(String x) throws Exception
{
URL oracle = new URL(x);
BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));
String inputLine=null;
StringBuffer theText = new StringBuffer();
while ((inputLine = in.readLine()) != null)
theText.append(inputLine+"\n");

String html = theText.toString();
in.close();

String[] tds = StringUtils.substringsBetween(html, "<tr>", "</tr>");

String[] tds2 = StringUtils.substringsBetween(tds[1], "href=\"/module/gallery", "\"><img");
String[] tds3 = StringUtils.substringsBetween(tds[1], "src='/redx_tools/mb_image.php", "' border='1'");

return ???

}

public static void main(String[] args) throws Exception {
String x = new String("http://www.wippro.at/module/gallery/index.php?limitstart=0&picno=0&gallery_key=59");

URLReader s = new URLReader();
for (String st : s.functie(x))
{
System.out.println(st);
}

}

}

最佳答案

你的琴弦是自己制作的吗?如果ab是你想要返回的String对象,你可以构建一个String数组来返回,如下所示:

return new String[] {a, b};

您已在代码中构建了三个字符串数组:tdstds2tds3。所有这些都可以在一个大数组中返回,如下所示:

String[] retArray = new String[tds.length+tds2.length+tds3.length];
System.arrayCopy(tds, 0, retArray, 0, tds.length);
System.arrayCopy(tds2, 0, retArray, tds.length, tds2.length);
System.arrayCopy(tds3, 0, retArray, tds.length+tds2.length, tds3.length);
return retArray

关于Java - 返回 2 个值(字符串数组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6864640/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com