String类中一些的方法的应用
一、整理string类
1、Length():获取字串长度;
2、charAt():获取指定位置的字符;
3、getChars():获取从指定位置起的子串复制到字符数组中;(它有四个参数)
4、replace():子串替换;
5、toUpperCase()、toLawerCase():大小写转换;
6、trim():去除头尾空格;
7、toCharArray():将字符串转换为字符数组。
二、String.equals()方法:
实现代码:public static void main(String args[])
string s1=new String("Hello");
string s2=new String("Hello");
System.out.println(s1==s2);
System.out.println(s1.equals(s2));
运行截图:
特别的:Equal的方法比较的是两个字符串的内容,而且只有当地址相同的前提下才能进行两者之间的比较,并且,在new新建的时候变量的地址不相同,因此,返回值不同。
在java中内容相同的字符串常量只保存一部分内容以节约内存,所以,没有new语句时,他们指向同一内存可以比较大小。
String类中一些的方法的应用的更多相关文章
- Java String类中的intern()方法
今天在看一本书的时候注意到一个String的intern()方法,平常没用过,只是见过这个方法,也没去仔细看过这个方法.所以今天看了一下.个人觉得给String类中加入这个方法可能是为了提升一点点性能 ...
- Java——String类中的compareTo方法总结
String类的定义: java.lang 类 String java.lang.Object java.lang.String 所有已实现的接口:Serializable, C ...
- String类中的equals()方法:
String类中的equals()方法: public boolean equals(Object anObject) { //如果是同一个对象 if (this == anObject) { ret ...
- Java用代码演示String类中的以下方法的用法
用代码演示String类中的以下方法的用法 (1)boolean isEmpty(): 判断字符串是不是空串,如果是空的就返回true (2)char charAt(int index): 返回索引上 ...
- String类中的equals()方法
在Java中,每一个对象都有一个地址空间,在这空间保存着这个对象的值. equals 比较的是值,==比较的地址以及值. 01: public class StringExample02: {03: ...
- 详解String类中的intern()方法
我们用一个经典的例子来理解 package com.jvm.heap; public class MyTest { public static void main(String[] args) { S ...
- String类中常用的方法(重要)
1.字符串与字节 public String(byte[] byte); 将全部字节变成字符串 public String (byte[] byte,int offset,int length) 将部 ...
- String类中的toCharArray()方法
toCharArray()方法 该方法的作用是返回一个字符数组,该字符数组中存放了当前字符串中的所有字符 public class toChar1{ public static void main( ...
- String类中常用的方法
@Test public void demo(){ // 以下为String中的常用的方法及注释, 最常用的注释前有**标注 String s = "abcdefg123456"; ...
随机推荐
- Robotium编写测试用例如何模拟Junit4的BeforeClass和AfterClass方法2 - SingleLaunchActivityTestCase
本文来源于:http://blog.csdn.net/zhubaitian/article/details/39296753 在上一遍笔记博客中本以为只能在Setup和TearDown中做条件判断来实 ...
- Open CV 图像显示(1)
演示:读入一张图片,并显示 #include "stdafx.h" #include <opencv2/core/core.hpp> #include ...
- BZOJ3542:DZY Loves March
询问是要求 $\sum_{i=1}^n((x[i]-a)^2+(y[i]-b)^2)(x[i]=a||y[i]=b)$ 即求 $\sum_{i=1}^n(x[i]-a)^2(y[i]=b)+\sum_ ...
- Codeforces Round #215 (Div. 2) C. Sereja and Algorithm
#include <iostream> #include <vector> #include <algorithm> #include <string> ...
- POJ 2955 Brackets(区间DP)
题目链接 #include <iostream> #include <cstdio> #include <cstring> #include <vector& ...
- URAL 1346. Intervals of Monotonicity(DP)
题目链接 错误的贪了一下,然后D了两下就过了.注意是不上升和不下降..不是上升和下降.. #include <cstring> #include <cstdio> #inclu ...
- Linux多线程实例练习 - pthread_create()
Linux多线程实例练习 pthread_create():创建一个线程 int pthread_create(pthread_t *tidp, const pthread_attr_t *attr, ...
- 人工智能 --test
http://zhidao.baidu.com/link?url=9qp_SbSRfzMezkD25FZiWyNDsMxgcK6lecYYt0SW1ESsqkRaV5LYQ-0ysk3F2e35ajA ...
- 关于Android2.X系统自定义图片圆角BUG的解决
今天在做项目的时候遇到的一个问题. 预期的效果是这样的:
- jQuery设计思想之取值和赋值
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...