Write a program in java to demonstrate remove duplication from ArrayList to TreeSet?

import java.util.*; public class ListAdd {       public static void main(String arg[])       {             Scanner in=new Scanner(System.in);             ArrayList ls=new ArrayList();             TreeSet set=new TreeSet();             ls.add("Vikrant");             ls.add("Manish");             ls.add("Suraj");             ls.add(3,"Amit");             ls.add("Manish");             ls.add("Kanir");             set.addAll(ls);             System.out.println("Total Number of Elements is "+ls.size());             Iterator l=ls.iterator();             while(l.hasNext())                   System.out.println(l.next());             … Continue reading Write a program in java to demonstrate remove duplication from ArrayList to TreeSet?

Advertisements

Write a program in java to demonstrate HashSet?

import java.util.*; public class ListHashSet {       public static void main(String arg[])       {             HashSet ListTreeSet=new HashSet();             System.out.println("Adding Kundan First Time "+ListTreeSet.add("Kundan"));             ListTreeSet.add("Suraj");             ListTreeSet.add("Manish");             ListTreeSet.add("Ankit");             System.out.println("Adding Kundan Second Time "+ListTreeSet.add("Kundan"));             System.out.println("Total Number In ListTreeSet "+ListTreeSet.size());             Iterator itr=ListTreeSet.iterator();             while(itr.hasNext())                   System.out.println(itr.next());       } }

Write a program in java to demonstrate TreeSet?

import java.util.*; public class ListTreeSet {       public static void main(String arg[])       {             TreeSet ListTreeSet=new TreeSet();             System.out.println("Adding Kundan First Time "+ListTreeSet.add("Kundan"));             ListTreeSet.add("Suraj");             ListTreeSet.add("Manish");             ListTreeSet.add("Ankit");             System.out.println("Adding Kundan Second Time "+ListTreeSet.add("Kundan"));             System.out.println("Total Number In ListTreeSet "+ListTreeSet.size());             Iterator itr=ListTreeSet.iterator();             while(itr.hasNext())                   System.out.println(itr.next());       } }

Write a program in java to demonstrate JDBC?

//    set classpath=C:oraclexeapporacleproduct10.2.0serverjdbclibojdbc14.jar //    set path=C:Program Files (x86)Javajdk1.7.0bin import java.sql.*; class JavaDataBase {       public static void main(String arg[])       {             try             {                   Class.forName("oracle.jdbc.driver.OracleDriver");                   Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");                   Statement stmt=con.createStatement();                   ResultSet rst=stmt.executeQuery("select * from emp");                   System.out.println("nID" +"t"+ "Name" +"tt"+ "Degree" +"t"+ "Salaryn");                   while(rst.next())                         System.out.println(rst.getInt(1) +"t"+ rst.getString(2) +"t"+ rst.getString(3) … Continue reading Write a program in java to demonstrate JDBC?

Write a program in java to prevent duplication from list?

import java.util.*; public class List {       public static void main(String arg[])       {             Scanner in=new Scanner(System.in);             ArrayList ls=new ArrayList();             int i=0;             while(i<5)             {                   System.out.print("Enter Name - ");                   String s=in.nextLine();                   if(true==ls.contains(s))                   {                         System.out.println("ntThis Name is Abailable in Data File, Try Another Namen");                         continue;                   … Continue reading Write a program in java to prevent duplication from list?

Write a program in java to demonstrate List Iterator?

import java.util.*; public class CollectionList {       public static void main(String arg[])       {             ArrayList ls=new ArrayList();             ls.add("Vikrant");             ls.add("Sunny");             ls.add("Kanir");             ls.add(1,"Abhinandan");             ls.add("Kundan");             System.out.println("Total Number of elements is "+ls.size());             System.out.println(ls.contains("Sunny"));             System.out.println(ls.contains("Vikash"));             Iterator itr=ls.iterator();             while(itr.hasNext())             {                   System.out.println("t"+itr.next());             }             ls.remove("Kanir");             System.out.println("Total Number … Continue reading Write a program in java to demonstrate List Iterator?

Write a program in java to send the message client to server?

Server import java.io.*; import java.net.*; public class Server {       public static void main(String arg[])       {             try             {                   System.out.println("Running Server");                   ServerSocket ss=new ServerSocket(7777);                   Socket s=ss.accept();                   DataInputStream dis=new DataInputStream(s.getInputStream());                   String str=(String)dis.readUTF();                   System.out.println("Message = "+str);                   ss.close();             }             catch(Exception e)             {                   System.out.println(e);             } … Continue reading Write a program in java to send the message client to server?

Write a program to find out IP address of current system?

import java.net.InetAddress; class IPFinder {       public static void main(String arg[])       {             try             {                   InetAddress address=InetAddress.getByName(arg[0]);                   System.out.println("IP Address is "+address.getHostAddress());             }             catch(Exception e)             {                   System.out.println(e);             }       } } //java IPFinder localhost //java IPFinder Vikrant-PC

Write a program in java to display addition of two numbers in applet and numbers must be given at compile time?

import java.applet.*; import java.awt.*; /*       <applet code="ParamApplet" width=400 height=300>       <param name="num1" value=20>       <param name="num2" value=30>       </applet> */ public class ParamApplet extends Applet {       int a,b,c;       public void init()       {             setBackground(Color.red);             setForeground(Color.yellow);             a=Integer.parseInt(getParameter("num1"));             b=Integer.parseInt(getParameter("num2"));             c=a+b;       }       public void paint(Graphics g)       { … Continue reading Write a program in java to display addition of two numbers in applet and numbers must be given at compile time?

Write a program in java to demonstrate simple applet program? In this program we have simple demonstrate a simple frame. Applet program method must be in an applet package.

import java.applet.*; /*       <applet code="SimpleApplet" width=400 height=300>       </applet> */ public class SimpleApplet extends Applet {}