As salamo alaikum wa rahmatullah
Example of Array, Vector and Hash Table
package collections.demo;
import java.util.Hashtable;
import java.util.Vector;
public class CollectionDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[]=new int[] {1,2,3,4,5,6};
Vector<Integer> v=new Vector();
Hashtable <Integer,String> hTable=new Hashtable();
// Adding element into the vector
v.add(1);
v.add(2);
v.add(3);
System.out.println(v);
v.set(0, 3);
System.out.println(v);
// Adding element into the HashTable
hTable.put(1, "Selenium");
hTable.put(2, "Java");
hTable.put(3, "OOSPS");
hTable.put(4, "Selenium");
System.out.println(hTable);
String s=hTable.values().toString();
System.out.println("Values of Hash Table :- "+s);
// Array instance creation requires []
// While vector and HashTable require ()
// Vector element insertion required addElement()
// but HashTable element insertion require put()
// Accessing the first element of the
// array, vector and HashTable
System.out.println(arr[0]);
System.out.println(v.elementAt(0));
System.out.println(hTable.get(1));
}
}
--
Output
[1, 2, 3]
[3, 2, 3]
{4=Selenium, 3=OOSPS, 2=Java, 1=Selenium}
Values of Hash Table :- [Selenium, OOSPS, Java, Selenium]
1
3
Selenium
#kazonline #kazacademy
Jazak allah khair
Nice example
ReplyDeleteBetway app review 2021 - XN - eXbET
ReplyDeleteGet a 100% up to €100 in 다파벳 bonus money For your account, the bonus amount depends 1XBET on the クイーンカジノ bookmaker's current balance.