私はここで関連する質問を見つけようとしました。私はそれが一般的な質問だと思いますが、私はまだインターネット上で見つけることができない不運です。ベクトルは1つの位置に複数のデータを格納できますか?
ポイントには、id、lat、lonの3つの部分が含まれています。私はそれらを格納するために3つの分離ベクトルを使用しましたが、それらはお互いに関連しています。新しい点が見つかると、異なるベクトルに3回追加する必要があります。
3つのデータを3つのベクトルに分割するのではなく、1つのデータに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++;
}
これはのように聞こえます宿題。ヒントを使用するオブジェクト。 –
Vector>しかし理由がないかもしれませんpre_mature配列タイプ –
mKorbel
彼らはまだVectorを教えていますか? – aviad