Note that there are some explanatory texts on larger screens.

plurals
  1. POCan a Vector store more than one data in one position?
    text
    copied!<p>I have tried to find the related questions here. I think it is a common question but unlucky I still cannot find on the internet. </p> <p>A point contains 3 parts, id , lat and lon. I used 3 separated vectors to store them but they are related to each other. When a new point is found, it has to add 3 times in different vectors... </p> <p>I want to add 3 data into ONE vector rather than 3 separated vectors. Can Vector to do that ? or any other simple way to reach my goal ?</p> <p>Many Thanks !</p> <p>Here is my code:</p> <pre><code>public class Try01 { static Vector&lt;String&gt; id = new Vector&lt;String&gt;(); static Vector&lt;Double&gt; lat = new Vector&lt;Double&gt;(); static Vector&lt;Double&gt; lon = new Vector&lt;Double&gt;(); 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 &lt; 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++; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload