String exampleString = "hello";
exampleString += " world";
"Contains e:"+ exampleString.contains("e") + " length:" + exampleString.length();
import java.util.Date;
Date exampleDate = new Date();
"current time:" + exampleDate.toString() + " value:" + exampleDate.getTime();
import java.util.Arrays;
double[] exampleArray = new double[5];
for (int i=0; i
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
List exampleList = new ArrayList<>();
exampleList.addAll(Arrays.asList("a", "b", "c", "d", "e"));
exampleList.toString();
Math.E
Math.PI
Math.abs(-5.611)
Math.sqrt(9)
Math.cbrt(27)
Math.pow(2,5)
Math.exp(2)
Math.log(6)
Math.log10(6)
Math.cos(0)
Math.sin(9)
Math.tan(5)
Math.atan(-7.3)
Math.acos(0.5)
Math.asin(0.3)
Math.ceil(4.13)
Math.floor(4.67)
Math.round(4.83)
Math.random()
Math.max(1,-3)
Math.min(1,-3)
"Hello".equalsIgnoreCase("hello")
"Hello".equals("hello")
"Hello World! World is yourself.".replace("World", "Feeling");
"Hello World! World is yourself.".replace(/World/g, "Feeling");
"Hello".startsWith("h")
"Hello".endsWith("o")
"Hello".substring(2, 5)
"hello".charAt(2)
"hello".concat(" world")
"1,2,3,4".split(",")
"hello".indexOf("e")
"hello".lastIndexOf("l")
"hello".length()
"Hello".toLowerCase()
"Hello".toUpperCase()
"Hello".contains("el")
" Hello ".trim()
" ".isBlank()
"".isEmpty()
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
List exampleListC = new ArrayList<>();
exampleListC.addAll(Arrays.asList("a", "b", "c", "d", "e"));
String exampleStringC = "c";
exampleListC.contains(exampleStringC);
// MyBox library paths should have been added in JShell environment
import mara.mybox.tools.StringTools;
String exampleStringM = "abc1233hello";
String exampleRegexM = "\\S*3{2,}\\S*";
boolean exampleCaseInsensitiveM = true;
StringTools.match(exampleStringM,exampleRegexM,exampleCaseInsensitiveM);
// MyBox library paths should have been added in JShell environment
import mara.mybox.tools.StringTools;
String exampleStringI = "abc1233hello";
String exampleRegexI = "3{2}";
boolean exampleCaseInsensitiveI = true;
StringTools.include(exampleStringI,exampleRegexI,exampleCaseInsensitiveI);
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
List exampleListB = new ArrayList<>();
exampleListB.addAll(Arrays.asList("a", "b", "c", "d", "e"));
String exampleStringB = "c";
exampleListB.contains(exampleStringB) &&
(exampleListB.size() >= 8 || exampleStringB.length() != 1 || !exampleStringB.startsWith("h"));
double circleAreaByDiameter(double diameter) {
double radius = diameter / 2;
return Math.PI * radius * radius ;
}
circleAreaByDiameter(120) + circleAreaByDiameter(30)
import java.math.BigDecimal;
import java.math.RoundingMode;
double scale(double v, int scale) {
BigDecimal b = new BigDecimal(v);
return b.setScale(scale, RoundingMode.HALF_UP).doubleValue();
}
scale(Math.PI, 3)
import java.math.BigDecimal;
import java.math.RoundingMode;
double scale(double v, int scale) {
BigDecimal b = new BigDecimal(v);
return b.setScale(scale, RoundingMode.HALF_UP).doubleValue();
}
import java.text.DecimalFormat;
String formatDouble(double data, int scale) {
try {
String format = "#,###";
if (scale > 0) {
format += "." + "#".repeat(scale);
}
DecimalFormat df = new DecimalFormat(format);
return df.format(scale(data, scale));
} catch (Exception e) {
return e.toString();
}
}
double circleAreaByRadius(double radius) {
return Math.PI * radius * radius ;
}
formatDouble(circleAreaByRadius(273.4), 4)
import java.util.Date;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
String DatetimeFormat = "yyyy-MM-dd HH:mm:ss.SSS";
String datetimeToString(Date theDate, String format, TimeZone theZone) {
if (theDate == null || theZone == null) {
return null;
}
SimpleDateFormat formatter = new SimpleDateFormat(format);
formatter.setTimeZone(theZone);
String dateString = formatter.format(theDate);
return dateString;
}
datetimeToString(new Date(), DatetimeFormat, TimeZone.getDefault());
import java.util.regex.Matcher;
import java.util.regex.Pattern;
boolean match(String string, String find, boolean isRegex,
boolean dotAll, boolean multiline, boolean caseInsensitive) {
if (string == null || find == null || find.isEmpty()) {
return false;
}
try {
int mode = (isRegex ? 0x00 : Pattern.LITERAL)
| (caseInsensitive ? Pattern.CASE_INSENSITIVE : 0x00)
| (dotAll ? Pattern.DOTALL : 0x00)
| (multiline ? Pattern.MULTILINE : 0x00);
Pattern pattern = Pattern.compile(find, mode);
Matcher matcher = pattern.matcher(string);
return matcher.matches();
} catch (Exception e) {
return false;
}
}
match("Hello1233World", "\\S*3{2,}\\S*", true, true, true, true);
import java.util.regex.Matcher;
import java.util.regex.Pattern;
boolean include(String string, String find, boolean caseInsensitive) {
if (string == null || find == null || find.isEmpty()) {
return false;
}
try {
int mode = (caseInsensitive ? Pattern.CASE_INSENSITIVE : 0x00) | Pattern.MULTILINE;
Pattern pattern = Pattern.compile(find, mode);
Matcher matcher = pattern.matcher(string);
return matcher.find();
} catch (Exception e) {
return false;
}
}
include("Hello1233World", "3{2}", true);