Java访问字符串数组中的特定元素 [英] Java accessing specific element in array of strings
问题描述
我正在运行一个供自己使用的Web搜寻器.我下载了一个,并希望为其提供种子.我想提供约50颗种子.所以我创建了一个字符串数组.我想为爬虫每次通过我的for循环提供1个种子.我的代码是:
I am running a web crawler for my own use. I downloaded one and want to provide it with seeds. I want to provide it with around 50 seeds. So I created an array of strings. I want to provide the crawler with 1 seed each time it goes through my for loop. My code is :
String [] temp =新的String []{"http://www.random.org/"、"http://www.wikipedia.org/","http://www.jlworld.com/","http://www.frys.com/"};
String[ ] temp = new String[ ] {"http://www.random.org/","http://www.wikipedia.org/", "http://www.jlworld.com/","http://www.frys.com/"};
String [] urls = new字符串[temp.length];
String[ ] urls = new String[temp.length];
for (int i = 0; i <=temp.length; i++)
{
urls[i] = temp[i];
}
搜寻器需要将一个字符串分配给url.就像这样:
The crawler needs a string assigned to urls. So like :
String [] urls = new String [1];
String[ ] urls = new String[1];
urls [0] ="http://www.google.com/";
urls[0] = "http://www.google.com/";
所以它像那样工作.虽然我的代码遇到了出站异常.我想做的是,每当它通过for循环时,就为爬虫提供1种种子.任何帮助,将不胜感激!
So it works like that. I get an outofbounds exception though for my code. What I want to do is provide the crawler with 1 of the seeds each time it goes through the for loop. Any help on this would be appreciated!
推荐答案
for (int i = 0; i <=temp.length; i++)
应该是:
for (int i = 0; i <temp.length; i++)
这篇关于Java访问字符串数组中的特定元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!