public class string { public static void main (String [] args) { String sql="select abc from def where efg=1"; String sql2="select abc from def WHERE efg=1"; String str = sql2.toLowerCase(); int i = sql.indexOf("where"); int j = str.indexOf("where"); System.out.println(i); System.out.println(j); } }
int i= sql.toLowerCase().indexOf("where");
private Singleton(){}
//在自己内部定义自己一个实例,是不是很奇怪?
//注意这是private 只供内部调用
private static Singleton instance = new Singleton();
//这里提供了一个供外部访问本class的静态方法,可以直接访问
public static Singleton getInstance() {
return instance;
}
}
第二种形式:
public class Singleton {
private static Singleton instance = null;
public static synchronized Singleton getInstance() {
//这个方法比上面有所改进,不用每次都进行生成对象,只是第一次
//使用时生成实例,提高了效率!
if (instance==null)
instance=new Singleton();
return instance; }
}
然后再用indexof()来取where的位置
{
public static void main (String [] args)
{
String sql="select abc from def where efg=1";
String sql2="select abc from def WHERE efg=1";
String str = sql2.toLowerCase();
int i = sql.indexOf("where");
int j = str.indexOf("where");
System.out.println(i);
System.out.println(j); }
}
试试一楼的办法了.
所以他的办法是可行的
jFresH_MaN(TM) ( ) 信誉:135 你的办法好啊.采用了