String s1 = "abc";
String s2 = "abc";
System.out.println(s1==s2); //返回true string s1=‘abc’ string s2=‘abc’ string的值是存储于常量池里边的,当给string赋值的时候回先到常量池寻找是否有相同的值。 String s3 = new String("abc");
String s4 = new String("abc");
System.out.println(s3==s4); //返回false System.out.println(s3.equals(s4))//返回true

基础类型数据存储于栈空间 引用类型数据存储于堆空间

string s1=‘abc’ string s2=‘abc’ string的值是存储于常量池里边的,当给string赋值的时候回先到常量池寻找是否有相同的值。
equals方法: String里的equals方法重写了object对象里的equals方法
String里的equals方法第一步也是会判断地址值是否相等,相等返回true ,不相等再去判断里面的值是否相等。

str.length 返回整个字符串的长度。
str.trim 去掉字符串两边的空格
str.trim.length 返回整个字符串的长度
str.charAt(); 取出字符串中指定索引位置的字符
str.contains(CharSequence s); 当此字符串包含指定的 char 值时,返回 true。
str.startWith(String s); 判断字符串是否以括号中的字符串开始
str.endWith(String s); 判断字符串是否以括号中的字符串结束
replace(char o, char n); 将指定的字符替换掉指定的字符
replace(CharSequence o, CharSequence n); 将指定的字符串替换掉指定的字符串
split(String s); 将字符串分割成字符串
toUpperCase(); 将字符串转换成大写
toLowerCase(); 将字符串转换成小写
valueOf(any args); 
str.indexOf(String s); 返回指定子字符串在此字符串中第一次出现处的索引。
str.lastIndexOf(String s);返回指定子字符串在此字符串中最后一次出现处的索引。
str.substring(int i); 返回一个新的字符串,它是此字符串的一个子字符串
str.substring(int a, int b); str.substring( int beginIndex, int endIndex)

package com.test;

public class lianxi {
public static void main(String[] args) {
String str = "像勇士这样的球队,只有防守一松懈,他们才能抓住机会,"
+ "打完了三场,爵士还是没找到应对勇士的办法";
//"球队","机会"
System.out.println(str.indexOf("球队"));
System.out.println(str.indexOf("机会"));
System.out.println(str.lastIndexOf("勇士")); int m = str.indexOf("球队") + str.indexOf("机会") + str.lastIndexOf("勇士");
System.out.println(m);
System.out.println((char)m);
System.out.println(str.split(",")[4]); String[] newstr = str.split(""); //用空字符串将这一段话分割成多个以每一个字为一个字符串的数组。
String temp = "";
for (int i = 0; i < newstr.length; i++) {
if(newstr[i].equals("勇")) {
newstr[i] = "爵";
} else if(newstr[i].equals("爵")) {
newstr[i] = "勇";
}
temp+=newstr[i];
}
System.out.println(temp);
//勇士抓住机会,找到应对办法
System.out.print(str.substring(str.indexOf("勇士"),str.indexOf("勇士")+2));
System.out.print(str.substring(str.indexOf("抓住机会"),str.indexOf("抓住机会")+4));
System.out.print(str.substring(str.indexOf(","),str.indexOf(",")+1));
System.out.print(str.substring(str.indexOf("找到应对"),str.indexOf("找到应对")+4));
System.out.print(str.substring(str.indexOf("办法"),str.indexOf("办法")+2));
System.out.println(); String qqEmail = "123@qq.com";
System.out.println(qqEmail.substring(0,qqEmail.indexOf("@")));

  

//增强for循环
public class ForArray
{
public static void main(String[] args)
{
int[] arr = {1,2,3,4,5,6,7}; for(int a:arr)
{
System.out.print(a);
}
}
}
/*
for (循环变量类型 循环变量名称 : 要被遍历的对象) 循环体
例子中,
1.arr就是为 要被遍历的对象,可以是数组,集合
2.循环变量类型就是这个arr数组的数据类型,即int
3.循环变量名称就是a,这个可以自己定义
*/

  

包装类:
Integer.parseInt();

byte---Byte
short---Short
int---Integer
long---Long

float---Float
double---Double

boolean---Boolean

char---Character

System.out.println(Integer.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
System.out.println(Byte.MAX_VALUE);
System.out.println(Long.MIN_VALUE);
System.out.println(Long.MAX_VALUE);
System.out.println(Short.MIN_VALUE);
System.out.println(Short.MAX_VALUE);

System.out.println(Float.MIN_VALUE);
System.out.println(Float.MAX_VALUE);
System.out.println(Double.MIN_VALUE);
System.out.println(Double.MAX_VALUE);

//空心正方形(进入for循环先判断i的值,如果i的值在1~7之间而且j=0或者7的时候,那么打印出除了第一行与最后一行的※,当i=1或7的时候第一行跟最后一行的※都打印出来)
/*for( int i=0; i<8; i++){
if(i>0&&i<7){ //先判断 i的值是否在1-7这个区间,
for(int j=0;j<8;j++){
if(j==0||j==7){
System.out.print("*"+" ");}
else{
System.out.print(" "+" ");}
}
}else{
for( int l=0; l<8;l++){
System.out.print("*"+" ");
}
}System.out.println();
}*/ //输出空心菱形。
for( int i=4; i<7; i++){
for( int j=8;j>0;j--){
if(j==i||j==8-i){
System.out.print("*");
}else{
System.out.print(" ");
}
}System.out.println();
}
for( int i=1; i<5; i++){
for( int j=8;j>0;j--){
if(j==i||j==8-i){
System.out.print("*");
}else{
System.out.print(" ");
}
}System.out.println();
} //实心菱形
for( int i=4; i>0; i--){ //菱形的上半部分是随着i值得变动输出的*越来越多,所以i值应该是自减
for( int j=0;j<8;j++){
if(j>i&&j<8-i){
System.out.print("*");
}else{
System.out.print(" ");
}
}System.out.println();
}
for( int i=0; i<4; i++){
for( int j=0;j<8;j++){
if(j>i&&j<8-i){
System.out.print("*");
}else{
System.out.print(" ");
}
}System.out.println();
} }

  

最新文章

  1. PowerDesigner-VBSrcipt-自动设置主键,外键名等(SQL Server)
  2. SharePoint 2013开发入门探索(一)- 自定义列表
  3. codeforces 723B Text Document Analysis(字符串模拟,)
  4. Web程序员开发App系列 - 开发我的第一个App,源码下载
  5. JSP action elements - JavaBean
  6. javascript两行代码按指定格式输出日期时间
  7. Nginx+Tomcat动静态资源分离
  8. leetcode problem 6 ZigZag Conversion
  9. 【Unity3d游戏开发】游戏中的贝塞尔曲线以及其在Unity中的实现
  10. Python 的编码格式
  11. python 简单实现淘宝关键字商品爬取
  12. android api 镜像站
  13. Jmeter连接Redis,获取Redis数据集
  14. Spring4 MVC Hibernate4 maven集成
  15. JS中的三种弹出式消息提醒(警告窗口、确认窗口、信息输入窗口)的命令是什么?
  16. Unity之流光效果
  17. iOS 抓包
  18. Android中如何使用xmlns
  19. Javascript 对象复制(深浅拷贝)
  20. 记录一则ORA-600 [13011]错误

热门文章

  1. Extending sparklyr to Compute Cost for K-means on YARN Cluster with Spark ML Library
  2. Vue2.x中的Render函数
  3. 东正王增涛浅析OA信息化整合平台系统在企业中的应用价值
  4. Linux OS共享文件
  5. jquery 根据数据库值设置radio的选中
  6. dedecms做好的网站怎么上传到网上?
  7. dedecms搜索提示"关键字不能小于2个字节!"
  8. django 自定义过滤器(filter)处理较为复杂的变量的实例
  9. 简谈java 中的 继承和多态
  10. CentOS通过yum安装php7.0