Scanner input = new Scanner(System.in);
System.out.print("请输入一段字符:");
String s = input.next();
System.out.println("请输入要查询的字符串:");
String a = input.next();
int index = s.indexOf(a);
List ls = new ArrayList();
while (index >= 0)
{
ls.add(index);
index = s.indexOf(a, index + 1);
}
for(Object i : ls)
{
System.out.print(i + " ");
}