Tutorialspoint

Remove a key from TreeMap in Java

import java.util.*;
public class Demo{
   public static void main(String args[]){
      TreeMap<Integer,String> m = new TreeMap<Integer,String>();
      m.put(1,"India");
      m.put(2,"US");
      m.put(3,"Australia");
      m.put(4,"Netherlands");
      m.put(5,"Canada");
      System.out.println("TreeMap Elements = "+m);
      System.out.println("Removing a Key = "+m.remove(3));
      System.out.println("Updated TreeMap Elements = "+m);
   }
}

TreeMap in Java and add key-value pairs

import java.util.*;
public class Demo{
   public static void main(String args[]){
      TreeMap<Integer,String> m = new TreeMap<Integer,String>();
      m.put(1,"India");
      m.put(2,"US");
      m.put(3,"Australia");
      m.put(4,"Netherlands");
      m.put(5,"Canada");
      for(Map.Entry e:m.entrySet()){
         System.out.println(e.getKey()+" "+e.getValue());
      }
   }
}

Remove a value from TreeMap in Java

import java.util.*;
public class Demo{
   public static void main(String args[]){
      TreeMap<Integer,String> m = new TreeMap<Integer,String>();
      m.put(1,"PHP");
      m.put(2,"jQuery");
      m.put(3,"JavaScript");
      m.put(4,"Ruby");
      m.put(5,"Java");
      m.put(6,"AngularJS");
      m.put(7,"ExpressJS");
      System.out.println("TreeMap Elements...");
      Collection res = m.values();
      Iterator i = res.iterator();
      while (i.hasNext()){
         System.out.println(i.next());
      }
      System.out.println("TreeMap size = "+m.size());
      // Remove an element
      Object ob = m.remove(5);
      System.out.println("\nTreeMap after removing a single element...\n "+m);
      System.out.println("Size of TreeMap now = "+m.size());
   }
}

Retrieve TreeMap size in Java

import java.util.*;
public class Demo{
   public static void main(String args[]){
      TreeMap<Integer,String> m = new TreeMap<Integer,String>();
      m.put(1,"PHP");
      m.put(2,"jQuery");
      m.put(3,"JavaScript");
      m.put(4,"Ruby");
      m.put(5,"Java");
      m.put(6,"AngularJS");
      m.put(7,"ExpressJS");
      System.out.println("TreeMap Elements...\n"+m);
      System.out.println("\nSize of TreeMap: " + m.size());
   }
}

Java Program to get highest key stored in TreeMap

import java.util.*;
public class Demo{
   public static void main(String args[]){
      TreeMap<Integer,String> m = new TreeMap<Integer,String>();
      m.put(1,"PHP");
      m.put(2,"jQuery");
      m.put(3,"JavaScript");
      m.put(4,"Ruby");
      m.put(5,"Java");
      m.put(6,"AngularJS");
      m.put(7,"ExpressJS");
      System.out.println("TreeMap Elements...\n"+m);
      System.out.println("Highest key in TreeMap: " + m.lastKey());
   }
}

Retrieve the last element from a LinkedList in Java

import java.util.LinkedList;
public class Demo {
   public static void main(String[] args) {
		LinkedList<String> l = new LinkedList<String>();
		l.add("Andy");
		l.add("Sara");
		l.add("James");
		l.add("Betty");
		l.add("Bruce");
		System.out.println("The last element of the Linked List is : " + l.getLast());
   }
}

Delete first and last element from a LinkedList in Java

import java.util.LinkedList;
public class Demo {
   public static void main(String[] args) {
      LinkedList<String> l = new LinkedList<String>();
      l.add("Apple");
      l.add("Mango");
      l.add("Pear");
      l.add("Orange");
      l.add("Guava");
      System.out.println("The LinkedList is: " + l);
      l.removeFirst();
      l.removeLast();
      System.out.println("The LinkedList is: " + l);
   }
}

Add elements at beginning and end of LinkedList in Java

import java.util.LinkedList;
public class Demo {
   public static void main(String[] args) {
      LinkedList<String> l = new LinkedList<String>();
      l.add("Apple");
      l.add("Mango");
      l.add("Pear");
      System.out.println("The LinkedList is: " + l);
      l.addFirst("Orange");
      l.addLast("Guava");
      System.out.println("The LinkedList is: " + l);
   }
}

Bootstrap Components Web Icons

<html>
   <head>
      <link rel = "stylesheet" 
         href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
      
      <i.custom {font-size: 2em; color: blue;}>
   </head>
	
   <body>
      <i class = "glyphicon glyphicon-tree-deciduous custom"></i>
   </body>
	
</html>

Bootstrap Glyphicons color

<html>
   <head>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"><style>
      i.mysize {font-size: 6em; color: blue;}
      </style>
   </head>
 
   <body>
      <i class="glyphicon glyphicon-tree-deciduous mysize"></i>
   </body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.