Sie sind auf Seite 1von 11

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package advanced_java;

import java.util.ArrayList;

import java.util.Collections;

public class phonebook_entry

String name;

int ph_no;

public phonebook_entry()

public void setName(String pname)

name=pname;

public String getName()

return name;

public void setNumber(int pnum)

ph_no=pnum;

public int getNumber()

return ph_no;
}

public static void main(String[] args) {

ArrayList<phonebook_entry> listt=new ArrayList<phonebook_entry>();

phonebook_entry entry1=new phonebook_entry();

entry1.setName("Mahalakshmi");

entry1.setNumber(987654321);

listt.add(entry1);

phonebook_entry entry2=new phonebook_entry();

entry2.setName("Yogalakshmi");

entry2.setNumber(876545678);

listt.add(entry2);

phonebook_entry entry3=new phonebook_entry();

entry3.setName("Seethalakshmi");

entry3.setNumber(877545678);

listt.add(entry3);

phonebook_entry entry4=new phonebook_entry();

entry4.setName("UdahyaRaghav");

entry4.setNumber(636545678);

listt.add(entry4);

phonebook_entry entry5=new phonebook_entry();

entry5.setName("ShanmugaPriyan");

entry5.setNumber(909545678);

listt.add(entry5);

for (phonebook_entry entry :listt)

System.out.printf("Name:%s\t Phone_Number:%s\n",entry.getName(),entry.getNumber());

}
}

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package advanced_java;

/**

* @author mahavalliraj

*/

import java.util.PriorityQueue;

public class queue_priority {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

PriorityQueue<String> queue_list=new PriorityQueue<String>();

queue_list.add("Maha");

queue_list.add("Yoga");

queue_list.add("Vallli");

queue_list.add("Raj");

queue_list.add("Abi");
queue_list.add("Yasar");

queue_list.add("Benny");

System.out.println("Elements in queue:"+queue_list);

System.out.println("Remove elemnt"+queue_list.remove());

System.out.println("Elements in head position:"+queue_list.element());

System.out.println("Current Elements in a queue after removing the head:"+queue_list.peek());

System.out.println("head of the queue:"+queue_list.poll());

System.out.println("Elements in queue:"+queue_list);

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package advanced_java;

/**

* @author mahavalliraj

*/

import java.util.ArrayList;

import java.util.Collections;

public class cricket {

/**

* @param args the command line arguments

*/
public static void main(String[] args) {

// TODO code application logic here

ArrayList<String> list=new ArrayList<String>();

list.add("Sachin");

list.add("Virat");

list.add("Rahul");

list.add("Gambhir");

list.add("Dravid");

list.add("Raina");

list.add("Dhoni");

System.out.println("arraylist before swap:\n");

for(String str:list)

System.out.println(str);

Collections.swap(list,0,6);

System.out.println("arraylist after swap:\n");

for(String str:list)

System.out.println(str);

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.


*/

package advanced_java;

/**

* @author mahavalliraj

*/

import java.util.ArrayList;

import java.util.Collections;

public class searching {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

ArrayList<String> list=new ArrayList<String>();

list.add("Mahiima raj");

list.add("Yalli kuutyy");

list.add("Rahul varma");

list.add("vijay devarakonda");

System.out.println("ArrayList contains the string 'Mahiima raj':"+list.contains("Mahiima raj"));

System.out.println("ArrayList contains the string 'vijay devarakonda':"+list.contains("varma"));

System.out.println("ArrayList contains the string 'Rahul varma':"+list.contains("Rahul varma"));

System.out.println("Before sorting:\n");

for(String str: list)

System.out.println(str);

Collections.sort(list);

System.out.println("ArrayList in Ascending Order\n");


for(String str:list)

System.out.println(str);

ArrayList<Integer> list1=new ArrayList<Integer>();

list1.add(987654321);

list1.add(900087655);

list1.add(769054123);

list1.add(788856768);

System.out.println("7888 is present in arraylist:"+list1.contains(788856768));

System.out.println("9000 is present in arraylist:"+list1.contains(900087655));

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package advanced_java;

/**

* @author mahavalliraj

*/

import java.util.ArrayList;

import java.util.Collections;

public class books


{

int book_id;

String book_name,Author_name;

public books( int book_id,String book_name,String Author_name)

this.book_id=book_id;

this.book_name=book_name;

this.Author_name=Author_name;

public int getId()

return book_id;

public void setId(int book_id)

this.book_id=book_id;

public String getName()

return book_name;

public void setName(String book_name)

this.book_name=book_name;

public String getAuthor()

return Author_name;

public void setAuthor(String Author_name)


{

this.Author_name=Author_name;

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

ArrayList<books> list=new ArrayList<books>();

list.add(new books(1,"C programming","Baalaguruswamy"));

list.add(new books(2,"c++ programming","yashankt"));

list.forEach(books->{ System.out.println("Book_id:"+books.getId() +" ,Book_name:"+


books.getName() + ", Author_Name:"+books.getAuthor());});

/*System.out.println("Does list array contain 'C Programming':" +list.contains("C


programming"));*/

System.out.println("ArrayList contains the string 'C programming':"+list.contains("C#


programming"));

System.out.println("IndexOf 'C programming':"+ list.indexOf("C programming"));

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package advanced_java;
/**

* @author mahavalliraj

*/

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.ArrayList;

public class appointment /*implements Comparable<appointment>*/ {

private int id;

private String name;

private Date appointment;

public appointment(int idd,String a_name,Date datee)

/*super();*/

id=idd;

name=a_name;

appointment=datee;

/* @Override

public int compareTo(appointment app)

return this.getId().compareTo(app.getId());

}*/

public String toString() {

return "Employee [id=" + id + ", name=" + name + ", appointment=" + appointment + "]";

}
/**

* @param args the command line arguments

*/

public static void main(String[] args) throws ParseException {

// TODO code application logic here

Date date=new Date();

ArrayList<appointment> list=new ArrayList<appointment>();

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

list.add(new appointment(1,"Maha",formatter.parse("4/09/2019"))) ;

list.add(new appointment(2,"yoga",formatter.parse("6/09/2019")));

System.out.println("Date is: "+date);

/* while(true)

appointment app=list.poll();

System.out.println(e);

if(e==null)

break;

}*/

Das könnte Ihnen auch gefallen