日期:2014-05-20 浏览次数:20716 次
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
public class Test1 {
private static final String[] URL_NAMES = {
"http://javapuzzlers.com",
"http://apache2-snort.skybar.dreamhost.com",
"http://www.google.com",
"http://javapuzzlers.com",
"http://findbugs.sourceforge.net",
"http://www.cs.umd.edu"
};
public static void main(String[] args) throws MalformedURLException {
Set <URL> favorites = new HashSet <URL>();
for (String urlName : URL_NAMES)
favorites.add(new URL(urlName));
System.out.println(favorites.size());
}
}
import java.util.Random; public class Test2 { public static void main(String[] args) { Random rnd = new Random(); boolean toBe = rnd.nextBoolean(); Number result = (toBe || !toBe) ? new Integer(3) : new Float(1); System.out.println(result); } }
public Student get(Serializable id) { return (Student)getHibernateTemplate().load(Student.class, id); } public List<Student> getAll() { return (List<Student>)getHibernateTemplate().loadAll(Student.class); } public void save(Student stu) { getHibernateTemplate().saveOrUpdate(stu); } public void remove(Student stu) { getHibernateTemplate().delete(stu); } public void update(Student stu) { getHibernateTemplate().update(stu); }