//StringMisc.java

// This program demonstrates the length, charAt and getChars

// methods of the String class.

//

// Note: Method getChars requires a starting point

// and ending point in the String. The starting point is the

// actual subscript from which copying starts. The ending point

// is one past the subscript at which the copying ends.

import javax.swing.*;

public class StringMisc {

public static void main( String args[] )

{

String s1, output;

char charArray[];

s1 = new String( "hello there" );

charArray = new char[ 5 ];

// output the string

output = "s1: " + s1;

// test the length method

output += "\nLength of s1: " + s1.length();

// loop through the characters in s1 and display reversed

output += "\nThe string reversed is: ";

for ( int i = s1.length() - 1; i >= 0; i-- )

output += s1.charAt( i ) + " ";

// copy characters from string into char array

//四个参数的含义

//1.被拷贝字符在字串中的起始位置

//2.被拷贝的最后一个字符在字串中的下标再加1

//3.目标字符数组

//4.拷贝的字符放在字符数组中的起始下标

s1.getChars( 0, 5, charArray, 0 );

output += "\nThe character array is: ";

for ( int i = 0; i < charArray.length;i++ )

output += charArray[ i ];

JOptionPane.showMessageDialog( null, output,

"Demonstrating String Class Constructors",

JOptionPane.INFORMATION_MESSAGE );

System.exit( 0 );

}

}

}

  1. Length():获取字串长度  《空格也算他的长度》
  2. charAt():获取指定位置的字符
  3. getChars():获取从指定位置起的子串复制到字符数组中(它有四个参数,在示例中有介绍)
  4. replace():子串替换
  5. toUpperCase()、 toLowerCase():大小写转换
  6. trim():去除头尾空格:
  7. toCharArray():将字符串对象转换为字符数组

最新文章

  1. Kafka设计解析(二)- Kafka High Availability (上)
  2. Hadoop1.2.1 全集群3节点安装-rpm安装
  3. expdp\impdp及exp\imp
  4. 在Ubuntu6.06 在搭建SVN服务器及在windows建立svn+ssh客户端
  5. 你真的懂offset与scroll吗?
  6. [bzoj1088]扫雷
  7. [Swift]LeetCode564. 寻找最近的回文数 | Find the Closest Palindrome
  8. Json解析注解 ---@SerializedName
  9. Avro实现RPC
  10. 为什么需要micro-service构建平台
  11. HDU 1403 Longest Common Substring(最长公共子串)
  12. spring boot 无法启动
  13. ELK学习笔记之ELK架构与介绍
  14. COM/DCOM开发练习之进程内组件实例
  15. python3 ,AttributeError: module &#39;tensorflow&#39; has no attribute &#39;merge_summary&#39;
  16. VC++ 崩溃处理以及打印调用堆栈
  17. 【python】windows7下怎样安装whl
  18. BZOJ 1588 [HNOI2002]营业额统计(双向链表)
  19. 《DSP using MATLAB》示例Example7.22
  20. (数据科学学习手札16)K-modes聚类法的简介&amp;Python与R的实现

热门文章

  1. 无法从命令行或调试器启动服务,必须首先安装Windows服务(使用installutil.exe),然后用ServerExplorer、Windows服务器管理工具或NET START命令启动它
  2. 《BI那点儿事》SSRS图表和仪表——雷达图分析三国超一流谋士、统帅数据(图文并茂)
  3. Java设置环境变量的含义(JAVA_HOME,PATH,CLASSPATH)
  4. win10离线安装.net framework 3.5
  5. windows服务相关
  6. 父类方法中的this
  7. JS重要知识点
  8. 51nod 1158 全是1的最大子矩阵
  9. Javascript之运动框架2
  10. guava学习--FluentIterable