java 常用的类

一、日期操作:Calendar类和SimpleDateFormat类

    public void Test1()
{
Calendar calendar=Calendar.getInstance();
System.out.println(calendar.get(Calendar.DATE));
System.out.println(calendar.get(Calendar.DAY_OF_MONTH));
System.out.println(calendar.get(Calendar.DAY_OF_WEEK));
System.out.println(calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
}

二、Arrays类

    //数组排序
public void Test2()
{
String[] strings= {"德布劳内","梅西","萨拉赫","卢卡库"};
Arrays.sort(strings);
System.out.println(Arrays.asList(strings));
} //数组填充
public void Test3()
{
int[] num=new int[4];
String[] strings=new String[4];
Arrays.fill(num, 4);
System.out.println(Arrays.toString(num));
} //数组比较
public void Test4()
{
int[] num1=new int[5];
int[] num2=new int[5];
Arrays.fill(num1, 110);
Arrays.fill(num2, 110);
System.out.println(Arrays.equals(num1, num2));
}

三、Java 注释

public class Annotation {

    //方法重写
@Override
public String toString()
{
return "rubbish";
} //不建议使用
@Deprecated
public void TestMethod()
{
System.out.println("你是不是傻");
} //屏蔽编译警告信息
@SuppressWarnings(value="unchecked")
public void Method2()
{
System.out.println("就此结束");
} public void Test1()
{
String string="Color";
string.toString();
System.out.println(string);
} public static void main(String[] args)
{
Annotation obj=new Annotation();
obj.Method2();
}
}

四、常用类

1)Object类

主要的方法:clone()、equals()、hashCode()、toString()

2)获取键盘输入

    //Scanner获取键盘输入
public void Test2()
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
String str = sc.next();
System.out.println(str);
}
} //BufferedReader获取键盘输入
public void Test3() throws IOException
{
BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in)); String string=null;
string=bReader.readLine();
System.out.println("you are value:"+string);
}
上一篇:《DSP using MATLAB》示例Example4.3 双边序列


下一篇:简单实现springmvc框架(servlet+自定义注解)