Search wiring.org.co:

Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.

Class | Vector
Name |

### get()

Examples |
    Vector < int > intVector;

    void setup() {
      Serial.begin(9600);
      pinMode(WLED, OUTPUT);
      // turn ON wiring hardware LED
      digitalWrite(WLED, HIGH);

      // add 255 elements to the vector (from 0 to 254)
      for (int i=0; i<255; i++) {
        intVector.addElement(i);
      }

      Serial.print("The vector's capacity is: ");
      // print the vector's capacity
      Serial.println(intVector.capacity(), DEC);

      // check if contains number 15
      if (intVector.contains(15) == true) {
        Serial.println("The vector contains the element 15");
      }

      Serial.print("The vector's first element is: ");
      // print the vector's first element
      Serial.println(intVector.firstElement(), DEC);

      Serial.print("The vector's index for element 30 is: ");
      // print the vector's element at position 30
      Serial.println(intVector.indexOf(30), DEC);

      // check if vector has elements
      if (intVector.isEmpty() == false) {
        Serial.println("The vector has elements");
      }

      Serial.print("The vector's last element is: ");
      // print the vector's last element
      Serial.println(intVector.lastElement(), DEC);

      Serial.print("The vector's last index of 10 is: ");
      // print the vector's last index of 10
      Serial.println(intVector.lastIndexOf(10), DEC);

      Serial.print("The vector's size is: ");
      // print the vector's size
      Serial.println(intVector.size(), DEC);

      // if adding element is successful
      if (intVector.add(255) == true) {
        Serial.print("the element was added and now the vector's last element is: ");
        // print the vector's last element
        Serial.println(intVector.lastElement(), DEC);
      }

      intVector.addElement(256); // add another element
      Serial.print("now the vector's last element is: ");
      // print the vector's last element
      Serial.println(intVector.lastElement(), DEC);

      // insert a '0' at index 10
      intVector.insertElementAt(0, 10);

      int t = intVector.elementAt(10);  // get the element at index 10
      Serial.print("t is: ");
      Serial.println(t, DEC);  // print its value

      intVector.remove(10);   // remove element at position 10
      t = intVector.get(10);  // get the element at position 10
      Serial.print("t after remove is: ");
      Serial.println(t, DEC);  // print the element at position 10

      // remove element at position 10
      intVector.removeElementAt(10);
      // get the element at position 10
      t = intVector.get(10);
      // print the element at position 10
      Serial.print("t after removeElementAt is: ");
      Serial.println(t, DEC);

      // remove element with value '23' from the Vector
      if (intVector.removeElement(23)==true) {
        Serial.println("the element 23 was removed.");
      }

      // set element at postion 5 with value 10
      intVector.setElementAt(10, 5);
      // get the element at position 10
      t = intVector.get(5);
      Serial.print("element at index 5 is now: ");
      // print the element at position 10
      Serial.println(t, DEC);

      // clear all elements in the vector
      intVector.clear();
      Serial.print("The vector's size after clear is: ");
      // print the vector's size
      Serial.println(intVector.size(), DEC);
    }

    void loop() {

    }

Description | Returns the element at the specified position in this vector.
Syntax |
    get(index)
Parameters |

index | int: the index to examine

Returns | int, long or char: The element at the specified index.
Usage | Application

Updated on July 07, 2011 11:09:25pm PDT