Can i have placeholder for String java like we have in sql prepared statements?
Eg Conside that i have string St = "akkk ? la,ala ? " ,
now i want to set values of ? as i set it in sql prepared statement st.setStingValue(1,"akshay"); // do we have something like this? St.setStringValue(2,"anjaaa");
The "?" character is used for a placeholder, you can define as many placeholders you want, as shown below: String SQL = SELECT * from STOCKS WHERE TICKER=?
A placeholder expression provides a location in a SQL statement for which a third-generation language bind variable will provide a value. You can specify the placeholder expression with an optional indicator variable.
A Placeholder is a predefined location in a JSP that displays a single piece of web content at a time that is dynamically retrieved from the BEA Virtual Content Repository.
You can use String.format
String st = "akkk %s la,ala %s ";
String result = String.format(st, "First Val", "Second Val");
Alternatively, you can use numeric positions
String st = "akkk %1$s la,ala %2$s ";
String result = String.format(st, "First Val", "Second Val");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With