I have a problem with string comparison. For example, there is this string:
\"hello world i am from heaven\"
I want to search if this strin
I'm assuming the problems you're having with indexOf()
related to you using the character version (otherwise why would you be searching for w when looking for world?). If so, indexOf()
can take a string argument to search for:
String s = "hello world i am from heaven";
if (s.indexOf("world") != -1) {
// it contains world
}
as for log base 2, that's easy:
public static double log2(double d) {
return Math.log(d) / Math.log(2.0d);
}