Java·ºÐÍ·½·¨
package PairTestMyCode.copy;
import java.util.*;
public class PairTest2
{
public static void main(String[] args)
{
GregorianCalendar[] birthdays =
{
new GregorianCalendar(1906, Calendar.DECEMBER, 9), // G. Hopper
new GregorianCalendar(1815, Calendar.DECEMBER, 10), // A. Lovelace
new GregorianCalendar(1903, Calendar.DECEMBER, 3), // J. von Neumann
new GregorianCalendar(1910, Calendar.JUNE, 22), // K. Zuse
};
Pair<GregorianCalendar> mm = ArrayAlg.minmax(birthdays);
System.out.println("min = " + mm.getFirst().getTime());
System.out.println("max = " + mm.getSecond().getTime());
}
}
class ArrayAlg
{
/**
Gets the minimum and maximum of an array of objects of type T.
@param a an array of objects of type T
@return a pair with the min and max value, or null if a is
null or empty
*/
public static <T extends Comparable> Pair<T> minmax(T[] a)
{
if (a == null || a.length == 0) return null;
T min = a[0];
T max = a[0];
for (int i = 1; i < a.length; i++)
{
if (min.compareTo(a[i]) > 0) min = a[i];
if (max.compareTo(a[i]) < 0) max = a[i];
}
return new Pair<T>(min, max);
}
}
class Pair<T>
{
private T first;
private T second;
public Pair()
{
first = null;
second = null;
}
public Pair(T first, T second)
{
this.first = first;
this.second = second;
}
public T getFirst()
{
return first;
}
public T getSecond()
{
return second;
}
public void setFirst(T newValue)
{
first = newValue;
}
public void setSecond(T newValue)
{
second = newValue;
}
}
ÆäÖеÚ30ÐдúÂëÊÇpublic static <T extends Comparable> Pair<T> minmax(T[] a)
{
if (a == null || a.length == 0) return null;
T min = a[0];
T max = a[0];
for
Ïà¹ØÎĵµ£º
package com.yzy;
import java.util.regex.*;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Pattern p=Pattern.compile("^[a-z]+");
Matcher m=p.matcher("a233"); //true
//Matcher m=p.matcher("2233") ......
java socketͨÐÅ
TCP¿Í»§¶Ë£º
import java.net.*;
import java.io.*;
public class Client {
static Socket server;
public static void main(String[] args) throws Exception {
server = new Socket(InetAddress.getLocalHost(), 23);
BufferedReader in = new BufferedReader(new InputStreamReader ......
JAVA³ÌÐòµÄÍâ±í×ÜÊÇÒ»°åÒ»Ñ۵ģ¬¿´¶àÁËÄÑÃâÉóÃÀÆ£ÀÍ£¬Äܲ»ÄÜʹÎÒÃǵÄJAVA³ÌÐòÍâ¹Û±äµÃ¸üÃÀ¹Û¸ü¶ÀÌØÄØ£¿´ð°¸Êǿ϶¨µÄ£¬ÎÒÃÇ¿ÉÒÔÈÃJAVA³ÌÐò¸ù¾ÝͼƬÀ´Éú³É×Ô¶¨ÒåµÄ²»¹æÔò´°Ìå¡£±ÈÈçÏÂͼµÄÕâÖÖÍâ¹Û£º
ͼÖеÄÕâ¸öÈËÎï(ÀÙÃ×ÀòÑÇ)±ãÊǶ¨ÒåºÃµÄ²»¹æÔò´°Ì壬ÔõôÑù£¿ºÜƯÁÁ°É£¡ÄÇôÈÃÎÒÃÇ¿ªÊ¼Ñ§Ï°°É¡£
Ê×ÏÈÒªË ......
¾¡Á¿¸´ÓöÔÏ󣬶ø²»ÊÇ´´½¨ÐµĶÔÏó£¬ÌرðÊǵ±Ò»¸ö¶ÔÏóÊÇimmutable£¨²»¿É¸Ä±ä£©µÄʱºò¡£
ÈçString¶ÔÏó£¬
String s= new String(“String”); ǧÍò²»ÒªÕâÑù×ö£¬ÒòΪÕâÀïʵ¼ÊÉÏ´´½¨ÁËÁ½¸ö¶ÔÏó¡£
Òª±ÜÃâ³öÏÖÕâÑùµÄÇé¿ö£¬
1ÊÇ¿ÉÒÔÓþ²Ì¬¹¤³§º¯Êý£¬À´½â¾ö£¬ÈçÀà¿âÖеÄBoolean.valueOf(“true&rdqu ......
¼°Ê±Ïû³ý²»Ê¹ÓõĶÔÏóµÄÒýÓÃ, ÀíÂÛÉÏ, ´øÓÐÄÚ´æ¹ÜÀíµÄÓïÑÔÊDz»´æÔÚÄÚ´æÐ¹Â©µÄ, µ«ÊÇÈç¹û¶Ô¶ÔÏóµÄ²Ù×÷²»µ±,Ò²ÊÇ¿ÉÄÜ»áÔì³ÉÄÚ´æÐ¹Â©.
ÈçÓÐÒ»¸östack, Æäpopº¯ÊýÈçÏÂ.
public Object pop()
{
if( Element.length() == 0) return nu ......