Java学习笔记(一)

1.for each 的使用。

语法:for(type variable : collection){ some code;}

 用途:常用于循环读取数组、集合中的元素,但不能对元素进行修改。

	public void testForeach(){
		int[] array = {1,3,5,9,7};
		for(int i : array){
			System.out.println(i);
		}
	}//输出数组

//操作二维数组
	public void testForeach(){		
		int[][] array2 = {
				{2,55},
				{4,66},
				{6,77}
		};
		
		for(int[] i:array2){
			String s = "";
			for(int j:i){
				s += j+"-";
			}
			s = s.substring(0, s.length()-1);
			System.out.println(s);
		}
		
	}

2.匿名对象:没有名字的对象。在栈内存中,对象的具体内容在堆内存之中保存,没有栈内存指向堆内存空间,就是一个匿名对象。
好处:由于没有对应的栈内存指向,所以只能使用一次,一次之后就将成为垃圾,并且等待被GC回收释放。
eg:new Demo().function();

3.查找String内容的方法汇总。

方法说明
public boolean contains(CharSequence s)

Returns true if and only if this string contains

 the specified sequence of char values.(JDK1.5)

public int indexOf(String str)

the index of the first occurrence of the specified substring

, or -1 if there is no such occurrence.

public int indexOf(String str, int fromIndex)

the index of the first occurrence of the specified substring,

 starting at the specified index, or-1 if  there is no such occurrence.

public int lastIndexOf(String str)从后往前查询
public int lastIndexOf(String str,                     int fromIndex)指定位置从后往前前查询
public boolean startsWith(String prefix)查询字符串是否以某个字符串开头
public boolean startsWith(String prefix,
                          int toffset)
在指定位置开始查询字符串是否以某个字符串开头
public boolean endsWith(String suffix)是否以某个字符串结尾


4.window.location的使用
属性                  描述
hash                设置或获取 href 属性中在井号“#”后面的分段。
host                 设置或获取 location 或 URL 的 hostname 和 port 号码。
hostname      设置或获取 location 或 URL 的主机名称部分。
href                  设置或获取整个 URL 为字符串。
pathname      设置或获取对象指定的文件名或路径。
port                  设置或获取与 URL 关联的端口号码。
protocol          设置或获取 URL 的协议部分。
search            设置或获取 href 属性中跟在问号后面的部分。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值