我试图在这里找到相关的问题。我认为这是一个常见的问题,但不幸的是我仍然无法在互联网上找到。Vector可以在一个位置存储多个数据吗?
一个点包含3个部分,id,lat和lon。我使用了3个独立的矢量来存储它们,但是它们是相互关联的。当找到一个新点时,它必须在不同的向量中添加3次...
我想将3个数据添加到一个矢量而不是3个分离的矢量中。矢量可以做到这一点?或任何其他简单的方法来达到我的目标?
非常感谢!
这里是我的代码:
public class Try01 {
static Vector<String> id = new Vector<String>();
static Vector<Double> lat = new Vector<Double>();
static Vector<Double> lon = new Vector<Double>();
public static void main(String[] args) throws Exception {
// create an input source for target document and parse it
int counter=0;
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("data.xml"));
// get all tags in the document with the name link
NodeList links = doc.getElementsByTagName("node");
for(int i = 0; i < links.getLength(); i++) {
Element link = (Element) links.item(i);
//add part
id.add(link.getAttribute("id"));
lat.add(Double.parseDouble(link.getAttribute("lat")));
lon.add(Double.parseDouble(link.getAttribute("lon")));
//checking point: show the vector
System.out.println(counter + ") Vector = " + id.get(counter) + " and " + lat.get(counter) + " with " + lon.get(counter));
counter++;
}
这听起来像家庭作业。提示 - 使用对象。 – 2012-02-28 09:07:01
矢量<矢量
他们仍然教Vector? – aviad 2012-02-28 09:10:54