Java Program to Get the Last Element of Vector Using the LastElement() Method

You are currently viewing Java Program to Get the Last Element of Vector Using the LastElement() Method

Java program to get the last element of Vector using the lastElement() method

// Java program to get the last element of Vector 
// using the lastElement() method

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Vector < String > vec = new Vector < String > ();

    vec.add("CAR");
    vec.add("BUS");
    vec.add("BIKE");
    vec.add("BUS");
    vec.add("TRUCK");

    System.out.println("Last Element: " + vec.lastElement());
  }
}

Output

Last Element: TRUCK

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply