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 |
public int indexOf(String str, int fromIndex) | the index of the first occurrence of the specified substring, starting at the specified index, or |
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 属性中跟在问号后面的部分。