教程集 www.jiaochengji.com
教程集 >  脚本编程  >  java  >  正文 java 日期oct 学习笔记

java 日期oct 学习笔记

发布时间:2017-12-08   编辑:jiaochengji.com
教程集为您提供java 日期oct 学习笔记等资源,欢迎您收藏本站,我们将为您提供最新的java 日期oct 学习笔记资源
提供一篇java 日期的简单学习笔记,有需要的朋友可以参考一下。

String trim();
返回一个字符串,删除掉了头部和尾部的空格。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4480')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4480>

boolean startsWith(String prefix);

boolean endsWith(String suffix);

分别判断字符串是不是以prefix开头或者以suffix结尾。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy3903')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3903>

int indexOf(String str);

int indexOf(String str,int fromIndex);

int indexOf(int cp);

int indexOf(int cp,int fromIndex);


返回值是第一个子串的开始位置。如果需要返回最后一个子串的请使用lastIndexOf,参数表一致。

 

2.常用的API用代码写出来好了。自己试了一下,和C 的string操作很像。

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7082')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7082>

import java.lang.StringBuilder;

public class temp
{
    public static void main(String[] args)
    {
        StringBuilder builder = new StringBuilder();
       
        builder.append("string");
        builder.append('c');
        builder.setCharAt(2,'v');
        builder.insert(3,"ins");
        builder.insert(4,'a');
        builder.delete(4,6);//这句删除的是4和5,即删除4~6之间不包括6的部分。
       
       
        String str = builder.toString();
        System.out.println(str);
    }
}

3.如果需要使用Scanner读入数据,请在头文件中加入

import java.util.*;

PS:nextLine()的似乎和C 中的getline()在效果方面有些区别。假如刚刚在屏幕上输出了一个endl,那么下一次getline的时候会直接把这个endl读进字符串(至少OJ上有时会这样),而刚才的尝试中nextLine()不会有这个问题。

如果需要读入密码(非明文)的话可以采用java.lang.System和java.io.Console中的Console类:

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy6759')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy6759>

import java.util.*;
import java.lang.System;
import java.io.Console;

public class temp
{
    public static void main(String[] args)
    {
        Console cons = System.console();
        String username = cons.readLine("User name: ");
        char[] passwd = cons.readPassword("Password: ");
        System.out.println(passwd);
    }
}

您可能感兴趣的文章:
学习Linux系统日志管理
java 日期oct 学习笔记
webwork学习笔记
J2SE学习笔记--集合框架
J2EE学习笔记--MVC框架
Struts 学习笔记之Action
学习笔记之JAVA图形设计卷I AWT——第3章 图 形
Java入门笔记8_JavaTools
PHP 日期函数 学习笔记介绍
分享:JavaScript Date() 日期与时间

[关闭]
~ ~