Posts

Showing posts from October, 2018

StringBuffer In Java

StringBuffer In Java: package one; public class StringBuffer { public static void main(String[] args) { java.lang.StringBuffer sb=new java.lang.StringBuffer("Hello ");  System.out.println(sb.capacity()); sb.append("Java"); System.out.println(sb); sb.insert(2," haha "); System.out.println(sb); sb.replace(1, 4, "huhuhuhu"); System.out.println(sb); sb.ensureCapacity(10); System.out.println(sb.capacity()); sb.delete(1, 18); System.out.println(sb); System.out.println(sb.capacity()); sb.reverse(); System.out.println(sb); }  } 

Convert LinkList To ArrayList in Java

Convert LinkList To ArrayList in Java: package one; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class LinkToArray { public static void main(String[] args) {     LinkedList<String> linkedlist = new LinkedList<String>();     linkedlist.add("Sifat");     linkedlist.add("mohaiminur"); linkedlist.add("huda"); linkedlist.add("sakib"); linkedlist.add("robi"); List<String> list = new ArrayList<String>(linkedlist); for (String str : list){    System.out.println(str); } } }

HashMap In Java

package one; import java.util.Map; public class HashMap { public static void main(String[] args) { Map<Integer,String> map=new java.util.HashMap<Integer,String>(); map.put(1,"b1"); map.put(2,"b2"); map.put(3,"b3"); for(Integer i: map.keySet()) { System.out.println(map.get(i)); } } }