import java.util.*;
public class HelloWorld
{
public static void main(String[] args)
{
Set
Num n = new Num(2);
Num n1 = new Num(2);
/* set.add(n);
set.add(n);
System.out.println(set.size()); //1*/
set.add(n);
set.add(n1);
System.out.println(set.size()); //2
System.out.println(n.hashCode()); //1829164700
System.out.println(n1.hashCode()); //2018699554
System.out.println(Collections.frequency(set,n)); //1
// create array list object
List
// populate the list
arrlist.add("A");
arrlist.add("B");
arrlist.add("C");
arrlist.add("C");
arrlist.add("C");
// check frequensy of 'C'
int freq = Collections.frequency(arrlist, "C");
System.out.println("Frequency of 'C' is: "+freq);
System.out.println(arrlist.size());
for(String x : arrlist){System.out.println(x.hashCode());}
}
}
// this will become its own file too (and these can be in any order)
public class Num
{
private int x;
Num(int x){
this.x=x;
}
}
2
1829164700
2018699554
1
Frequency of 'C' is: 3
5
65
66
67
67
List
ll.add("one");
ll.add("two");
ll.add("three");
ll.add("four");
ll.add("two");
ll.add("three");
ll.add("two");
ll.add("one");
System.out.println("Actual list: "+ll);
System.out.println("Frequency of 'one': "+Collections.frequency(ll, "one"));
System.out.println("Frequency of 'three': "+Collections.frequency(ll, "three"));
System.out.println("Frequency of 'two': "+Collections.frequency(ll, "two"));
No comments:
Post a Comment