Java Code Snippet-10
/**
*
*/
package techyield;
/**
* @author satyanarayana gokavarapu
*
*/
public class Node {
public Node(int i) {
System.out.println("In Node class parameterized constructor "+i);
}
}
package techyield;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author satyanarayana gokavarapu
*
*/
public class Test{
public static void main(String[] args) {
// TODO Auto-generated method stub
List list = new ArrayList();
list.add(new Node(10));
list.add(new String("Krishna"));
System.out.println(list.get(1));
Set set = new HashSet();
set.add(new Node(1));
set.add(new Node(2));
set.add(new Node(2));
System.out.println("Length of set is "+set.size());
}
}
Select an answer
Please comment below if you have any doubts.