找到 34423 篇文章 关于编程

Java 中正则表达式“[^...]”结构

Maruthi Krishna
更新于 2019年11月19日 06:17:16

144 次浏览

子表达式/元字符“[^...]”匹配任何单个字符,但不包括括号中的字符。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class SpecifiedCharacters {    public static void main( String args[] ) {       String regex = "[^hwtyoupi]";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }输出匹配数:21示例 2以下 Java 程序接受… 阅读更多

Java 中正则表达式“re*”元字符

Maruthi Krishna
更新于 2019年11月18日 11:59:46

116 次浏览

子表达式/元字符“re*”匹配前一个表达式的 0 次或多次出现。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "aabc*";       String input = "aabcabcaabcabbcaabcbcaabc";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }输出匹配数:4示例 2import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchAllCharacters ... 阅读更多

何时在 Java 中使用 @ConstructorProperties 注解与 Jackson?

raja
更新于 2020年7月9日 07:19:56

2K+ 次浏览

@ConstructorProperties 注解来自 java.beans 包,用于通过带注解的构造函数将 JSON 反序列化为 Java 对象。此注解自 Jackson 2.7 版本起支持。此注解的工作方式非常简单,无需为构造函数中的每个参数添加注解,我们可以为每个构造函数参数提供一个包含属性名称的数组。语法@Documented @Target(value=CONSTRUCTOR) @Retention(value=RUNTIME) public @interface ConstructorProperties示例import com.fasterxml.jackson.databind.ObjectMapper; import java.beans.ConstructorProperties; public class ConstructorPropertiesAnnotationTest {    public static void main(String args[]) throws Exception {       ObjectMapper mapper = new ObjectMapper();       Employee emp = new Employee(115, "Raja");       String jsonString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(emp);   ... 阅读更多

解释 Java 中正则表达式“\A”元字符

Maruthi Krishna
更新于 2019年11月18日 11:57:12

188 次浏览

子表达式/元字符“\A”匹配整个字符串的开头。如果在正则表达式中使用它,它将匹配输入字符串中紧随其后的句子。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "\AHi";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }输出匹配数:1示例2以下 Java 程序接受一个字符串… 阅读更多

Java 中正则表达式“.”(点)元字符

Maruthi Krishna
更新于 2019年11月18日 10:29:25

1K+ 次浏览

子表达式/元字符“.”匹配任何单个字符,但换行符除外。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatchesAll {    public static void main( String args[] ) {       String regex = ".";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;       }       System.out.println("Number of matches: "+count);    } }输出匹配数:40示例 2以下 Java 程序接受 5… 阅读更多

Java 中正则表达式“$”(美元符)元字符

Maruthi Krishna
更新于 2019年11月18日 10:17:40

903 次浏览

子表达式/元字符“$”匹配行尾。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class EndWith {    public static void main( String args[] ) {       String regex = "Tutorialspoint$";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;          System.out.println("Number of matches: "+count);       }    } }输出匹配数:1示例 2以下 Java 程序接受… 阅读更多

Java 中正则表达式“^”(插入符)元字符

Maruthi Krishna
更新于 2019年11月18日 10:12:52

518 次浏览

子表达式/元字符“^”匹配行首。如果在正则表达式中使用它,它将匹配输入字符串中紧随其后的句子。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexExample {    public static void main( String args[] ) {       String regex = "^Hi how are you";       String input = "Hi how are you welcome to Tutorialspoint";       Pattern p = Pattern.compile(regex);       Matcher m = p.matcher(input);       int count = 0;       while(m.find()) {          count++;     ... 阅读更多

如何在 Java 中使用 Gson 向 JSON 字符串添加/插入附加属性?

raja
更新于 2020年2月19日 10:28:54

8K+ 次浏览

com.google.gson.JSonElement 类表示 Json 的一个元素。我们可以使用 Gson 类的 toJsonTree() 方法将对象的表示形式序列化为 JsonElements 的树。我们可以使用 JSonElement 的 getAsJsonObject() 方法向 JSON 字符串添加/插入附加属性。此方法返回获取元素作为 JsonObject。语法public JsonObject getAsJsonObject()示例import com.google.gson.*; public class AddPropertyGsonTest {    public static void main(String[] args) {       Gson gson = new GsonBuilder().setPrettyPrinting().create();// 美化打印 JSON       Student student = new Student("Adithya");       String jsonStr = gson.toJson(student, Student.class);       System.out.println("JSON String: " + jsonStr);       ... 阅读更多

Java 中快速失败和安全失败的区别

Mahesh Parahar
更新于 2019年11月18日 07:31:59

3K+ 次浏览

序号|关键点|快速失败|安全失败|1|异常|当线程正在迭代集合时,如果对集合进行任何更改(例如添加、删除和更新),快速失败将抛出并发修改异常。安全失败不会抛出异常。|2|集合类型|ArrayList 和 HashMap 集合是快速失败迭代器的示例。|CopyOnWrite 和并发修改是安全失败迭代器的示例。|3|性能和内存|它直接操作实际集合。因此,此迭代器不需要额外的内存和时间。|它操作的是集合的副本而不是实际集合。在时间和内存方面存在开销。|4|修改|迭代器不允许在迭代过程中修改集合。安全失败迭代器允许…… 阅读更多

Spring框架中Application context和BeanFactory的区别

Mahesh Parahar
更新于 2019年11月18日 07:28:36

4K+ 浏览量

Spring框架提供两个IOC容器来管理、配置和操作Bean。一个是BeanFactory,另一个是Application Context。Application context接口扩展了BeanFactory,以增强BeanFactory的功能。在新的Spring版本中,BeanFactory被ApplicationContext取代。但是,BeanFactory仍然存在,以保持向后兼容性。Spring 2.0及以上版本使用BeanPostProcessor扩展点(一个接口,提供一些回调方法,我们可以实现这些方法来自定义实例化逻辑、依赖关系解析逻辑等)。因此,如果您使用的是BeanFactory,则某些功能(例如AOP和事务)将无法工作,除非进行一些额外的配置。序号|关键点|BeanFactory|Application… 阅读更多

广告
© . All rights reserved.