看结果1?

package com.swift;

class ArrayString {
public static void main(String[] args) {
String str = "swift:30|sunny:28|Ben:32";
String str1[] = str.split("\\|");
for (int i = 0; i <= str1.length - 1; i++) {
String str2[] = str1[i].split("\\:"); System.out.println("名字是" + str2[0] + "-->" + "年龄是" + str2[1]);
System.out.println(); }
}
}

看结果2?

package com.swift;

class StringEmail
{
public static void main(String[] args)
{
String email="tiankong_0000@sina.com.cn";
String email1="81257211@qq.com";
String email2="tiankong.sina.com";
String email3="81257211@sina";
String email4="qq.com@81257211";
String email5="@.";
System.out.println(operate(email));
System.out.println(operate(email1));
System.out.println(operate(email2));
System.out.println(operate(email3));
System.out.println(operate(email4));
System.out.println(operate(email5)); }
public static boolean operate(String str)
{
boolean flag=true;
if (str.indexOf("@")==-1)
{
flag=false;
}
if (str.indexOf(".")==-1)
{
flag=false;
}
if (str.indexOf(".")<=str.indexOf("@"))
{
flag=false;
}
return flag;
} }

看结果3?

package com.swift;

class StringEquals
{
public static void main(String[] args)
{
String str="Hello";
String str1=new String("Hello");
if(str.equals(str1))
System.out.println("111111111");
else
System.out.println("00000000000");
}
}

看结果4?

package com.swift;

public class StringResult {
String str = new String("good");
char[] ch = { 'a', 'b', 'c' }; public static void main(String args[]) {
StringResult sr = new StringResult();
sr.change(sr.str, sr.ch);
System.out.print(sr.str + "and");
System.out.print(sr.ch);
} public void change(String str, char ch[]) {
str = "test ok";
ch[0] = 'g';
}
}

看结果5?

package com.swift;

class StringJudge
{
public static void main(String[] args)
{
String str1="Hello";
String str2=new String(" World");
System.out.println(str1+str2);
String a="ok";
String b="ok";
String c=new String ("ok");
if(a==b)
System.out.println("1");
else
System.out.println("0");
if(a==c)
System.out.println("1");
else
System.out.println("0");
if(b==c)
System.out.println("1");
else
System.out.println("0"); if(a.equals(b))
System.out.println("1");
else
System.out.println("0");
if(a.equals(c))
System.out.println("1");
else
System.out.println("0");
if(b.equals(c))
System.out.println("1");
else
System.out.println("0");
}
}

如何解释?

不同的是,第一条先在内存中创建了"ok"这个String,然后将reference赋给a,下一条语句String b = "ok";那么JVM将不再创建"ok",而是直接将第一个"ok"的reference赋给b,也就是说,a和b是使用同一块内存,而String c = new String("ok");那JVM将在内存中再创建一块区域放上“ok”这个字符串。

看结果6?

package com.swift;

  public class Emp {
    int x=10;
  }

public class ParameterTest {
public static void main(String[] args) {
Emp d = new Emp();
d.x = 30;
fun(d);
System.out.println(d.x);
} public static void fun(Emp example) {
example.x = 100;
} }

看结果7?

package com.swift;

public class ParameterTest {
public static void main(String[] args) {
String str="Hello";
fun(str);
System.out.println(str);
} public static void fun(String temp)
{
temp="World";
} }

看结果8?

class Emp
{
String x="swift";
}
class Chuandi
{
public static void main(String[] args)
{
Emp d=new Emp();
d.x="who";
fun(d);
System.out.println(d.x);
}
public static void fun(emp example)
{
example.x="is";
}
}

看结果,测试?java中的String类 字符串拆分成字符串数组 判定邮箱地址 字符串比较 参数传递?的更多相关文章

  1. 关于Java中的String类知识点小总结

    Java中的String类知识点 前言 在 Java 中字符串属于对象,Java 提供了 String 类来创建和操作字符串. 如何创建字符串 最简单的方式 String str = "he ...

  2. Java中的String类

    /*String类用于描述字符串事物的那么它就提供了多个方法对字符串进行操作 方法都会用,字符串这块就结束了常见的操作有哪些?“abcd”它应该具备什么功能,我们才能更好得操作它?1.获取(必须要掌握 ...

  3. JAVA中的String类(详解)

    Java.lang.String类是final类型的,因此不可以继承这个类.不能修改这个类.String是一个类不属于基本数据类型. 可以从源码中看到,String是一个final类型. String ...

  4. Java中的String为什么要设计成不可变的?

    一.不可变类和不可变对象 Normally,you create an object and allow its contents to be changed later.However ,occas ...

  5. java中的String类常量池详解

    test1: package StringTest; public class test1 { /** * @param args */ public static void main(String[ ...

  6. Java中的String类能否被继承?为什么?

    不能被继承,因为String类有final修饰符,而final修饰的类是不能被继承的. Java对String类的定义: public final class String implements ja ...

  7. Java 中的 String 类常用方法

    字符串广泛应用在Java编程中,在Java中字符串属于对象,String 类提供了许多用来处理字符串的方法,例如,获取字符串长度.对字符串进行截取.将字符串转换为大写或小写.字符串分割等. Strin ...

  8. 为什么Java中的String类是不可变的?

    String类是Java中的一个不可变类(immutable class). 简单来说,不可变类就是实例在被创建之后不可修改. 在<Effective Java> Item 15 中提到了 ...

  9. java中的String类的不可变性的小例子

    在java语言中,String类具有不可变性,即常量字符串不可更改.下面的一个小例子简单演示相关概念. public class test { public static void main(Stri ...

随机推荐

  1. [Xcode 实际操作]九、实用进阶-(19)重写父类的绘图方法,使用图形上下文绘制自定义图形

    目录:[Swift]Xcode实际操作 本文将演示如何使用图形上下文,绘制自定义图形. 使用快捷键[Command]+[N]创建一个新的类文件. (在项目文件夹[DemoApp]上点击鼠标右键[New ...

  2. 【BZOJ1174】: [Balkan2007]Toponyms

    →原题← ↑这样子我就不复制题面啦~ 就是一题很裸的字典树而已,不过空间卡的很死,直接开个数组 tr[N][52] 什么之类的一定会RE的(惨痛的教训) 当字典树空间不够而时间限制又比较宽松时,我们可 ...

  3. Tomcat - ClassFormatException的解决方法

    问题与分析 在使用Tomcat7运行web项目时报错如下: 严重: Compilation error org.eclipse.jdt.internal.compiler.classfmt.Class ...

  4. max函数的用法

    题目是   给你一段全英文本,求这段文本中出现次数最多的字母 import string def checkio(text): text = text.lower() return max(strin ...

  5. jsp内置对象分析

    1.html表单的提交方式比较: 1.1.get方式:将表单内容经过编码之后 ,通过URL发送, 使用get方式发送时有255个字符的限制. 1.2.post方式:将表单的内容通过http发送,pos ...

  6. Virtual Judge使用指南

    https://cn.vjudge.net/ Virtual Judge并不是常规的Online Judge平台,他通过爬取其他OJ的题目,让我们可以直接在VJ上查找并提交各种OJ的题目,然后将我们的 ...

  7. 手动释放Linux内存

    查看内存: [root@iZ9dp52tlpqyihuisujjswZ bin]# free -h total used free shared buff/cache available Mem: 3 ...

  8. 关于Mybatis的一点小记录(parameterType)

    1.Mybatis的parameterType有两个比较常用的,一个是类的对象,还有一个就是Map,然后取值的方法也很简单: 基本数据类型:#{参数} 获取参数中的值 复杂数据类型:#{属性名} ,m ...

  9. python_17(sql)

    第1章 MySQL安装 1.1 windows版下载地址 1.2 添加环境变量 1.3 初始化 1.4 启动mysql服务 1.5 链接mysql 1.6 制作mysql的windows服务 1.7 ...

  10. MVC验证注解(不包含自定义验证)