-
How to Searching a String?
String string = "aString";// First occurrence.int index = string.indexOf('S'); // 1// Last occurrence.index = string.lastIndexOf('i'); // 4// Not found.index = string.lastIndexOf('z'); // -1
-
Replacing Characters in a String
// Replace all occurrences of 'a' with 'o'String newString = string.replace('a', 'o');Replacing Substrings in a Stringstatic String replace(String str,String pattern, String replace) {int s = 0;int e = 0;StringBuffer result = new StringBuffer();while ((e = str.indexOf(pattern, s)) >= 0) {result.append(str.substring(s, e));result.append(replace);s = e+pattern.length();}result.append(str.substring(s));return...
-
How do I instantiate a bean whose constructor accepts parameters using the useBean tag?
Consider the following bean: package bar;public class FooBean {public FooBean(SomeObj arg) {...}//getters and setters here}The only way you can instantiate this bean within your JSP page is to use a scriptlet. For example, the following snippet creates the bean with session scope:&l;% SomeObj x = new SomeObj(...);bar.FooBean foobar = new FooBean(x);session.putValue("foobar",foobar);%> You can...
Interests Interview Questions
Ans