Skip to content

Commit 60561ae

Browse files
authored
Add files via upload
1 parent 475058b commit 60561ae

File tree

79 files changed

+4627
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4627
-0
lines changed

Array/Array.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
author: Jaydatt Patel
3+
Array Declaration and access.
4+
Stntax:
5+
<data_type> <variable_name>[];
6+
<data_type>[] <variable_name>;
7+
<data_type> []<variable_name>;
8+
*/
9+
10+
class Array {
11+
//generic print function for array for Integer,Double,String
12+
public static <T> void print_list(T i[])
13+
{
14+
System.out.print("\nElements"+"["+i.length+"]: ");
15+
for(T x : i)
16+
System.out.print(x+", ");
17+
}
18+
19+
public static class myclass{
20+
int id;
21+
String name;
22+
myclass(int a, String b)
23+
{
24+
id = a;
25+
name = b;
26+
}
27+
}
28+
29+
public static void main(String args[])
30+
{
31+
32+
int i_list1[] = {1,2,3,4,5};
33+
int i_list2[] = new int[] {11,22,33};
34+
System.out.print("\ni_list1[i]: ");
35+
for(int i = 0; i < i_list1.length; i++)
36+
System.out.print( i_list1[i]+", ");
37+
System.out.print("\ni_list2[i]: ");
38+
for(int i = 0; i < i_list2.length; i++)
39+
System.out.print( i_list2[i]+", ");
40+
41+
Integer[] i_arr1 = new Integer[10];
42+
Integer[] i_arr2 = new Integer[]{101,102,103};
43+
for(int i = 0; i < i_arr1.length; i++)
44+
i_arr1[i] = i+1;
45+
print_list(i_arr1);
46+
print_list(i_arr2);
47+
48+
Double[] d_arr1 = new Double[10];
49+
Double[] d_arr2 = new Double[]{101.1,102.2,103.3};
50+
for(int i = 0; i < d_arr1.length; i++)
51+
d_arr1[i] = i+0.123;
52+
print_list(d_arr1);
53+
print_list(d_arr2);
54+
55+
String[] s_arr1 = new String[2];
56+
s_arr1[0] = "aaa";
57+
s_arr1[1] = "bbb";
58+
String[] s_arr2 = new String[]{"AAA","BBB","CCC"};
59+
print_list(s_arr1);
60+
print_list(s_arr2);
61+
62+
myclass[] mc = new myclass[4];
63+
mc[0] = new myclass(1,"A");
64+
mc[1] = new myclass(2,"B");
65+
mc[2] = new myclass(3,"C");
66+
mc[3] = new myclass(4,"D");
67+
68+
for(int i = 0; i < mc.length; i++)
69+
System.out.println("mc["+i+"]: id = "+mc[i].id+", name: "+mc[i].name);
70+
71+
myclass[] mc2 = new myclass[]{new myclass(11, "AA"),new myclass(12, "BB")};
72+
for(int i = 0; i < mc2.length; i++)
73+
System.out.println("mc2["+i+"]: id = "+mc2[i].id+", name: "+mc2[i].name);
74+
75+
}
76+
}

Array_multi/Array_multi.java

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
author: Jaydatt Patel
3+
Array multi dimension Declaration and access.
4+
Stntax:
5+
<data_type> <variable_name>[][];
6+
<data_type> []<variable_name>[];
7+
<data_type>[][] <variable_name>;
8+
9+
*/
10+
11+
class Array_multi {
12+
13+
//generic print function for multidimension array for Integer,Double,String
14+
public static <T> void print_list(T[][] list)
15+
{
16+
System.out.print("\nElements"+": ");
17+
for(T row[] : list)
18+
{
19+
System.out.print("\n");
20+
for(T cell : row)
21+
System.out.print(cell+", ");
22+
}
23+
}
24+
25+
26+
public static class myclass
27+
{
28+
int id;
29+
String name;
30+
myclass(){};
31+
myclass(int a, String b)
32+
{
33+
id = a;
34+
name = b;
35+
}
36+
}
37+
38+
public static void main(String args[])
39+
{
40+
int int_list[][] = new int[4][5];
41+
int q = 0;
42+
//get data of array by length of array
43+
for(int row = 0; row < int_list.length; row++)
44+
{
45+
q += 10;
46+
for(int col = 0; col < int_list[row].length; col++)
47+
int_list[row][col] = q+col;
48+
}
49+
50+
//print the data of array by length of array
51+
System.out.print("\n\nint_list[][]: ");
52+
for(int row = 0; row < int_list.length; row++)
53+
{
54+
System.out.print("\n");
55+
for(int col = 0; col < int_list[row].length; col++)
56+
System.out.print(" "+int_list[row][col]);
57+
}
58+
59+
//declare flexible multidimension array method-1.
60+
Integer int_list1[][] = new Integer[3][];
61+
int_list1[0] = new Integer[2];
62+
int_list1[1] = new Integer[5];
63+
int_list1[2] = new Integer[3];
64+
q = 0;
65+
for(int row = 0; row < int_list1.length; row++)
66+
{
67+
q += 100;
68+
for(int col = 0; col < int_list1[row].length; col++)
69+
int_list1[row][col] = q+col;
70+
}
71+
System.out.print("\n\nint_list1[][]: ");
72+
print_list(int_list1);
73+
74+
//declare flexible multidimension array method-2.
75+
Integer arrRef[] = {31,32,33,34};
76+
Integer int_list2[][] = {
77+
{1,2,3},
78+
{11,12,13,14,15,16},
79+
{21,22},
80+
arrRef,
81+
null};
82+
int_list2[4] = new Integer[] {51,52,53};
83+
System.out.print("\n\nint_list2[][]: ");
84+
print_list(int_list2);
85+
86+
Double d_list[][] = new Double[3][];
87+
d_list[0] = new Double[2];
88+
d_list[1] = new Double[5];
89+
d_list[2] = new Double[3];
90+
q = 0;
91+
for(int row = 0; row < d_list.length; row++)
92+
{
93+
q += 10.0;
94+
for(int col = 0; col < d_list[row].length; col++)
95+
d_list[row][col] = (double)q + (double)col;
96+
}
97+
System.out.print("\n\nd_list[][]: ");
98+
print_list(d_list);
99+
100+
String arrRefstr[] = {"a4","b4","c4","d4"};
101+
String str_list[][] = {
102+
{"a1","b1","c1"},
103+
{"a2","b2","c2","d2","e2","f2"},
104+
{"a3","b3"},
105+
arrRefstr,
106+
null};
107+
str_list[4] = new String[]{"a5","b5","c5"};
108+
System.out.print("\n\nstr_list[][]: ");
109+
print_list(str_list);
110+
111+
myclass mc_list[][] = new myclass[4][];
112+
mc_list[0] = new myclass[2];
113+
mc_list[1] = new myclass[4];
114+
mc_list[2] = new myclass[5];
115+
mc_list[3] = new myclass[3];
116+
q = 0;
117+
for(int row = 0; row < mc_list.length; row++)
118+
{
119+
q += 100;
120+
for(int col = 0; col < mc_list[row].length; col++)
121+
{
122+
mc_list[row][col] = new myclass();
123+
mc_list[row][col].id = q+col;
124+
mc_list[row][col].name = ("Name"+ (q+col));
125+
}
126+
}
127+
128+
System.out.print("\n\nmc_list[][]: ");
129+
for(int row = 0; row < mc_list.length; row++)
130+
{
131+
System.out.print("\n");
132+
for(int col = 0; col < mc_list[row].length; col++)
133+
{
134+
System.out.print("(id: "+mc_list[row][col].id + ", " +
135+
"name: "+mc_list[row][col].name +"), ");
136+
}
137+
}
138+
139+
}
140+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
class Check_data_type{
3+
4+
public static void main(String args[]) {
5+
6+
int intData = 15;
7+
float floatData = 20.5f;
8+
char charData = 'X';
9+
10+
Integer integerData = 25;
11+
Double doubleData = 35.5;
12+
String str = "Hello";
13+
14+
// show datatypes of variables by using getClass() and getSimpleName() methods
15+
System.out.println(intData + " is of type " + ((Object)intData).getClass().getSimpleName());
16+
System.out.println(floatData + " is of type " + ((Object)floatData).getClass().getSimpleName());
17+
System.out.println(charData + " is of type " + ((Object)charData).getClass().getSimpleName());
18+
System.out.println(integerData + " is of type " + integerData.getClass().getSimpleName());
19+
System.out.println(doubleData + " is of type " + doubleData.getClass().getSimpleName());
20+
System.out.println(str + " is of type " + str.getClass().getSimpleName());
21+
}
22+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
author: Jaydatt Patel
3+
4+
Collection:
5+
The Collection in Java is a framework that provides an architecture to store and manipulate the group of objects.
6+
Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.Java Collection means a single unit of objects.
7+
8+
Java Collection framework provides many interfaces :
9+
List : class (ArrayList, Vector, LinkedList)
10+
Set : class (HashSet, LinkedHashSet,TreeSet)
11+
Map : class (HashMap, LinkedHashMap,TreeMap)
12+
Queue : class (LinkedList, PriorityQueue)
13+
Deque : class (ArrayDeque,Deque)
14+
15+
Methods of the Collection Interface :
16+
17+
1.add(Object) : This method is used to add an object to the collection.
18+
2.addAll(Collection c) : This method adds all the elements in the given collection to this collection.
19+
3.clear() : This method removes all of the elements from this collection.
20+
4.contains(Object o) : This method returns true if the collection contains the specified element.
21+
5.containsAll(Collection c) : This method returns true if the collection contains all of the elements in the 6given collection.
22+
7.equals(Object o) : This method compares the specified object with this collection for equality.
23+
8.hashCode() : This method is used to return the hash code value for this collection.
24+
9.isEmpty() : This method returns true if this collection contains no elements.
25+
10.iterator() : This method returns an iterator over the elements in this collection.
26+
11.max() :
27+
This method is used to return the maximum value present in the collection.
28+
12.parallelStream() : This method returns a parallel Stream with this collection as its source.
29+
13.remove(Object o) : This method is used to remove the given object from the collection. If there are duplicate values, then this method removes the first occurrence of the object.
30+
14.removeAll(Collection c) : This method is used to remove all the objects mentioned in the given collection from the collection.
31+
15.removeIf(Predicate filter) : This method is used to remove all the elements of this collection that satisfy the given predicate.
32+
16.retainAll(Collection c) : This method is used to retain only the elements in this collection that are contained in the specified collection.
33+
17.size() : This method is used to return the number of elements in the collection.
34+
18.spliterator() : This method is used to create a Spliterator over the elements in this collection.
35+
19.stream() : This method is used to return a sequential Stream with this collection as its source.
36+
20.toArray() : This method is used to return an array containing all of the elements in this collection.
37+
38+
Iterator interface:
39+
Iterator interface provides the facility of iterating the elements in a forward direction only.
40+
Methods in the Iterator interface:
41+
1. public boolean hasNext(): It returns true if the iterator has more elements otherwise it returns false.
42+
2. public Object next(): It returns the element and moves the cursor pointer to the next element.
43+
3. public void remove(): It removes the last elements returned by the iterator. It is less used.
44+
45+
*/
46+
47+
import java.util.*;
48+
class Course{
49+
String course;
50+
Course(){
51+
course = "Invalid";
52+
}
53+
Course(String s){
54+
course = s;
55+
}
56+
}
57+
58+
class Student{
59+
int id;
60+
String name;
61+
Course Degree = new Course();
62+
Student(){}
63+
Student(int i,String nm,String Course){
64+
id = i;
65+
name = nm;
66+
Degree.course = Course;
67+
}
68+
}
69+
70+
class Collection_Deque_ArrayDeque {
71+
public static void main(String args[]){
72+
73+
Deque<Student> dq_arr = new ArrayDeque<Student>();
74+
75+
System.out.println("dq_arr.isEmpty(): "+dq_arr.isEmpty());
76+
77+
Student st1 = new Student(101,"Amit","BBA");
78+
Student st2 = new Student(102,"Rahul","BCA");
79+
Student st3 = new Student(103,"Ravi","BCOM");
80+
Student st4 = new Student(104,"Mayur","MCA");
81+
Student st5 = new Student(105,"Jignesh","MBA");
82+
Student st6 = new Student(106,"Sagar","MCOM");
83+
84+
dq_arr.add(st1);
85+
dq_arr.add(st2);
86+
dq_arr.add(st3);
87+
dq_arr.addFirst(st4); // insert at start position
88+
dq_arr.addLast(st5); //insert at end position
89+
dq_arr.push(st6); //insert at end position
90+
91+
int size = dq_arr.size();
92+
System.out.println("List size : " + size);
93+
94+
System.out.println("After Add: ");
95+
for(Student s : dq_arr){
96+
System.out.println("id: "+ s.id + ", name: "+ s.name +", degree: " + s.Degree.course);
97+
}
98+
99+
Student temp = new Student();
100+
101+
temp = dq_arr.peek(); // return head
102+
System.out.println("Head : " + temp.id + ", "+ temp.name);
103+
temp = dq_arr.peekFirst(); //return first object
104+
System.out.println("First : " + temp.id + ", "+ temp.name);
105+
temp = dq_arr.peekLast(); //return last object
106+
System.out.println("Last : " + temp.id + ", "+ temp.name);
107+
108+
109+
temp = dq_arr.pop(); //remove first element
110+
System.out.println("pop : " + temp.id + ", "+ temp.name);
111+
temp = dq_arr.poll(); // remove the head
112+
System.out.println("poll : " + temp.id + ", "+ temp.name);
113+
temp = dq_arr.pollFirst(); //remove the first element
114+
System.out.println("pollFirst : " + temp.id + ", "+ temp.name);
115+
temp = dq_arr.pollLast(); //remove last element
116+
System.out.println("pollLast : " + temp.id + ", "+ temp.name);
117+
118+
temp = dq_arr.removeFirst(); //remove first element
119+
System.out.println("removeFirst : " + temp.id + ", "+ temp.name);
120+
temp = dq_arr.removeLast(); //remove last element
121+
System.out.println("removeLast : " + temp.id + ", "+ temp.name);
122+
dq_arr.remove(st3);
123+
124+
System.out.println("After Remove: ");
125+
for(Student s : dq_arr){
126+
System.out.println("id: "+ s.id + ", name: "+ s.name +", degree: " + s.Degree.course);
127+
}
128+
129+
dq_arr.clear(); //remove all elements
130+
131+
132+
}
133+
}

0 commit comments

Comments
 (0)