Top Related Projects
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
Google core libraries for Java
Apache Commons Lang
Spring Framework
Main Portal page for the Jackson project
Apache Commons IO
Quick Overview
Hutool is a comprehensive Java utility library that aims to simplify development by providing a wide range of tools and helper methods. It covers various aspects of Java programming, including string manipulation, date handling, file operations, network utilities, and more, all designed to improve code readability and reduce boilerplate.
Pros
- Extensive collection of utility methods covering many common programming tasks
- Well-documented with clear examples and explanations
- Actively maintained with regular updates and improvements
- Lightweight and easy to integrate into existing projects
Cons
- Some developers may prefer using separate, specialized libraries for specific tasks
- Learning curve for developers unfamiliar with the library's structure and naming conventions
- Potential for dependency conflicts with other libraries that provide similar functionality
- May introduce unnecessary dependencies for projects that only need a small subset of features
Code Examples
- String manipulation:
String result = StrUtil.format("Hello, {}! Today is {}", "World", DateUtil.today());
System.out.println(result);
This example demonstrates string formatting and date handling using Hutool's StrUtil
and DateUtil
classes.
- File operations:
File file = FileUtil.file("example.txt");
FileUtil.writeUtf8String("Hello, Hutool!", file);
String content = FileUtil.readUtf8String(file);
System.out.println(content);
This code snippet shows how to create a file, write content to it, and read from it using Hutool's FileUtil
class.
- HTTP requests:
String result = HttpUtil.get("https://api.example.com/data");
JSONObject json = JSONUtil.parseObj(result);
System.out.println(json.getStr("key"));
This example demonstrates making an HTTP GET request and parsing the JSON response using Hutool's HttpUtil
and JSONUtil
classes.
Getting Started
To use Hutool in your project, add the following dependency to your Maven pom.xml
file:
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.18</version>
</dependency>
For Gradle, add this to your build.gradle
file:
implementation 'cn.hutool:hutool-all:5.8.18'
After adding the dependency, you can start using Hutool's utility classes in your Java code by importing the required classes:
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.date.DateUtil;
// Import other Hutool classes as needed
Competitor Comparisons
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
Pros of Fastjson
- Faster JSON parsing and serialization performance
- More extensive JSON-specific features and customization options
- Better support for complex JSON structures and data types
Cons of Fastjson
- Narrower focus on JSON processing compared to Hutool's broader utility offerings
- Less frequent updates and maintenance in recent years
- Some security vulnerabilities have been reported in the past
Code Comparison
Fastjson:
String jsonString = JSON.toJSONString(object);
MyObject myObject = JSON.parseObject(jsonString, MyObject.class);
Hutool:
String jsonString = JSONUtil.toJsonStr(object);
MyObject myObject = JSONUtil.toBean(jsonString, MyObject.class);
Summary
Fastjson excels in JSON processing with superior performance and features, while Hutool offers a broader range of utility functions beyond JSON handling. Fastjson is ideal for projects with heavy JSON requirements, whereas Hutool provides a more comprehensive toolkit for various Java development needs. The choice between the two depends on the specific requirements of your project and the balance between specialized JSON capabilities and general-purpose utilities.
Google core libraries for Java
Pros of Guava
- More comprehensive and mature library with a wider range of utilities
- Better documentation and extensive JavaDoc
- Strong support from Google and a large community
Cons of Guava
- Larger library size, which may increase application footprint
- Steeper learning curve due to its extensive API
- Less frequent updates compared to Hutool
Code Comparison
Guava:
List<String> list = Lists.newArrayList("a", "b", "c");
Multimap<String, Integer> multimap = ArrayListMultimap.create();
Optional<String> optional = Optional.of("value");
Hutool:
List<String> list = CollUtil.newArrayList("a", "b", "c");
Dict dict = Dict.create().set("key", "value");
Optional<String> optional = Optional.ofNullable("value");
Summary
Guava is a more established and feature-rich library, offering a wide range of utilities backed by Google. It provides excellent documentation but comes with a larger footprint and steeper learning curve. Hutool, on the other hand, is a lighter alternative with more frequent updates and a focus on simplicity. The choice between the two depends on project requirements, team familiarity, and performance considerations.
Apache Commons Lang
Pros of Commons Lang
- Mature and well-established project with a long history of development and community support
- Extensive documentation and widespread adoption in the Java ecosystem
- Rigorous testing and quality assurance processes as part of the Apache Software Foundation
Cons of Commons Lang
- More focused on core Java language utilities, lacking some of the broader functionality found in Hutool
- Less frequent updates and slower adoption of new Java features compared to Hutool
- Larger dependency size due to its comprehensive nature
Code Comparison
Commons Lang:
String result = StringUtils.capitalize("hello");
boolean isEmpty = StringUtils.isEmpty(myString);
String[] parts = StringUtils.split("a,b,c", ",");
Hutool:
String result = StrUtil.upperFirst("hello");
boolean isEmpty = StrUtil.isEmpty(myString);
String[] parts = StrUtil.split("a,b,c", ",");
Both libraries offer similar functionality for common string operations, but Hutool tends to have more concise method names. Commons Lang provides a wider range of utilities specifically for Java language features, while Hutool covers a broader spectrum of utility functions beyond just language-specific operations.
Spring Framework
Pros of Spring Framework
- Comprehensive ecosystem with extensive documentation and community support
- Robust dependency injection and aspect-oriented programming features
- Seamless integration with various Java EE technologies and third-party libraries
Cons of Spring Framework
- Steeper learning curve due to its complexity and vast feature set
- Heavier footprint and potential performance overhead for smaller applications
- More verbose configuration and setup compared to lightweight alternatives
Code Comparison
Spring Framework:
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, World!";
}
}
Hutool:
public class HelloServer {
public static void main(String[] args) {
HttpUtil.createServer(8080)
.addAction("/hello", (req, res) -> res.write("Hello, World!"))
.start();
}
}
Spring Framework offers a more structured and annotation-based approach, while Hutool provides a simpler and more concise method for creating a basic HTTP server. Spring's approach is better suited for larger, enterprise-level applications, whereas Hutool's simplicity makes it ideal for smaller projects or quick prototyping.
Main Portal page for the Jackson project
Pros of Jackson
- Widely adopted industry standard for JSON processing in Java
- Extensive ecosystem with numerous modules for various data formats
- High performance and flexibility for complex data structures
Cons of Jackson
- Steeper learning curve for advanced features
- Can be overkill for simple JSON operations
- Requires more configuration for custom serialization/deserialization
Code Comparison
Jackson:
ObjectMapper mapper = new ObjectMapper();
MyObject obj = mapper.readValue(jsonString, MyObject.class);
String json = mapper.writeValueAsString(obj);
Hutool:
JSONObject jsonObject = JSONUtil.parseObj(jsonString);
MyObject obj = JSONUtil.toBean(jsonObject, MyObject.class);
String json = JSONUtil.toJsonStr(obj);
Summary
Jackson is a powerful and versatile JSON processing library, while Hutool is a comprehensive utility library that includes JSON handling among many other features. Jackson excels in complex JSON operations and offers more customization options, but Hutool provides a simpler API for basic JSON tasks and includes a wide range of other utility functions. The choice between them depends on the specific project requirements and the need for additional utility functions beyond JSON processing.
Apache Commons IO
Pros of Commons IO
- More mature and widely adopted in the Java ecosystem
- Focused specifically on I/O operations, providing deep functionality
- Backed by the Apache Software Foundation, ensuring long-term support
Cons of Commons IO
- Limited scope compared to Hutool's broader utility offerings
- Less frequent updates and releases
- Larger dependency size for projects only needing basic I/O operations
Code Comparison
Commons IO:
FileUtils.copyFile(srcFile, destFile);
String content = FileUtils.readFileToString(file, "UTF-8");
IOUtils.closeQuietly(inputStream);
Hutool:
FileUtil.copy(srcFile, destFile, true);
String content = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
IoUtil.close(inputStream);
Summary
Commons IO is a specialized library for I/O operations, offering deep functionality and widespread adoption. Hutool, on the other hand, is a more comprehensive utility library that includes I/O operations among many other features. While Commons IO benefits from Apache's backing and maturity, Hutool provides a broader range of utilities in a single package. The choice between them depends on project requirements and whether a focused I/O library or a more general-purpose utility suite is needed.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð¬A set of tools that keep Java sweet.
ð https://hutool.cn/ ð
ðç®ä»
Hutool
æ¯ä¸ä¸ªåè½ä¸°å¯ä¸æç¨çJavaå·¥å
·åºï¼éè¿è¯¸å¤å®ç¨å·¥å
·ç±»ç使ç¨ï¼æ¨å¨å¸®å©å¼åè
å¿«éã便æ·å°å®æåç±»å¼åä»»å¡ã
è¿äºå°è£
çå·¥å
·æ¶µçäºå符串ãæ°åãéåãç¼ç ãæ¥æãæ件ãIOãå å¯ãæ°æ®åºJDBCãJSONãHTTP客æ·ç«¯çä¸ç³»åæä½ï¼
å¯ä»¥æ»¡è¶³åç§ä¸åçå¼åéæ±ã
ðHutoolå称çç±æ¥
Hutool = Hu + toolï¼æ¯åå ¬å¸é¡¹ç®åºå±ä»£ç å¥ç¦»åçå¼æºåºï¼âHuâæ¯å ¬å¸å称ç表示ï¼toolè¡¨ç¤ºå·¥å ·ãHutoolè°é³âç³æ¶âï¼ä¸æ¹é¢ç®æ´ææï¼ä¸æ¹é¢å¯æâé¾å¾ç³æ¶âã
ðºHutoolç念
Hutool
æ¢æ¯ä¸ä¸ªå·¥å
·éï¼ä¹æ¯ä¸ä¸ªç¥è¯åºï¼æ们ä»ä¸èªè¯©ä»£ç ååï¼å¤§å¤æ°å·¥å
·ç±»é½æ¯æ¬è¿èæ¥ï¼å æ¤ï¼
- ä½ å¯ä»¥å¼å ¥ä½¿ç¨ï¼ä¹å¯ä»¥æ·è´åä¿®æ¹ä½¿ç¨ï¼è**ä¸å¿ æ 注任ä½ä¿¡æ¯**ï¼åªæ¯å¸æè½æbugåæ¶åé¦åæ¥ã
- æ们åªåå¥å ¨ä¸æ注éï¼ä¸ºæºç å¦ä¹ è æä¾è¯å¥½å°å¦ä¹ ç¯å¢ï¼äºååå°äººäººé½è½çå¾æã
ð ï¸å å«ç»ä»¶
ä¸ä¸ªJavaåºç¡å·¥å ·ç±»ï¼å¯¹æ件ãæµãå å¯è§£å¯ã转ç ãæ£åã线ç¨ãXMLçJDKæ¹æ³è¿è¡å°è£ ï¼ç»æåç§Utilå·¥å ·ç±»ï¼åæ¶æä¾ä»¥ä¸ç»ä»¶ï¼
模å | ä»ç» |
---|---|
hutool-aop | JDKå¨æ代çå°è£ ï¼æä¾éIOCä¸çåé¢æ¯æ |
hutool-bloomFilter | å¸éè¿æ»¤ï¼æä¾ä¸äºHashç®æ³çå¸éè¿æ»¤ |
hutool-cache | ç®åç¼åå®ç° |
hutool-core | æ ¸å¿ï¼å æ¬Beanæä½ãæ¥æãåç§Utilç |
hutool-cron | å®æ¶ä»»å¡æ¨¡åï¼æä¾ç±»Crontab表达å¼çå®æ¶ä»»å¡ |
hutool-crypto | å å¯è§£å¯æ¨¡åï¼æä¾å¯¹ç§°ãé对称åæè¦ç®æ³å°è£ |
hutool-db | JDBCå°è£ åçæ°æ®æä½ï¼åºäºActiveRecordææ³ |
hutool-dfa | åºäºDFA模åçå¤å ³é®åæ¥æ¾ |
hutool-extra | æ©å±æ¨¡åï¼å¯¹ç¬¬ä¸æ¹å°è£ ï¼æ¨¡æ¿å¼æãé®ä»¶ãServletãäºç»´ç ãEmojiãFTPãåè¯çï¼ |
hutool-http | åºäºHttpUrlConnectionçHttp客æ·ç«¯å°è£ |
hutool-log | èªå¨è¯å«æ¥å¿å®ç°çæ¥å¿é¨é¢ |
hutool-script | èæ¬æ§è¡å°è£ ï¼ä¾å¦Javascript |
hutool-setting | åè½æ´å¼ºå¤§çSettingé ç½®æ件åPropertieså°è£ |
hutool-system | ç³»ç»åæ°è°ç¨å°è£ ï¼JVMä¿¡æ¯çï¼ |
hutool-json | JSONå®ç° |
hutool-captcha | å¾çéªè¯ç å®ç° |
hutool-poi | é对POIä¸ExcelåWordçå°è£ |
hutool-socket | åºäºJavaçNIOåAIOçSocketå°è£ |
hutool-jwt | JSON Web Token (JWT)å°è£ å®ç° |
å¯ä»¥æ ¹æ®éæ±å¯¹æ¯ä¸ªæ¨¡ååç¬å¼å
¥ï¼ä¹å¯ä»¥éè¿å¼å
¥hutool-all
æ¹å¼å¼å
¥ææ模åã
ðææ¡£
ðªæ¯æHutool
ð³æèµ
å¦æä½ è§å¾Hutoolä¸éï¼å¯ä»¥æèµ è¯·ç»´æ¤è åå è¾£æ¡~ï¼å¨æ¤è¡¨ç¤ºæè°¢^_^ã
ðå¨è¾¹ååº
ä½ ä¹å¯ä»¥éè¿è´ä¹°Hutoolçå¨è¾¹ååæ¥æ¯æHutoolç»´æ¤å¦ï¼
æ们æä¾äºå°æHutool Logoçå¨è¾¹ååï¼æ¬¢è¿ç¹å»è´ä¹°æ¯æï¼
ð Hutool å¨è¾¹ååº ð
ð¦å®è£
ðMaven
å¨é¡¹ç®çpom.xmlçdependenciesä¸å å ¥ä»¥ä¸å 容:
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.32</version>
</dependency>
ðGradle
implementation 'cn.hutool:hutool-all:5.8.32'
ð¥ä¸è½½jar
ç¹å»ä»¥ä¸é¾æ¥ï¼ä¸è½½hutool-all-X.X.X.jar
å³å¯ï¼
ðï¸æ³¨æ Hutool 5.xæ¯æJDK8+ï¼å¯¹Androidå¹³å°æ²¡ææµè¯ï¼ä¸è½ä¿è¯ææå·¥å ·ç±»æå·¥å ·æ¹æ³å¯ç¨ã å¦æä½ ç项ç®ä½¿ç¨JDK7ï¼è¯·ä½¿ç¨Hutool 4.xçæ¬ï¼ä¸åæ´æ°ï¼
ð½ç¼è¯å®è£
访é®HutoolçGitee主页ï¼https://gitee.com/dromara/hutool ä¸è½½æ´ä¸ªé¡¹ç®æºç ï¼v5-masteræv5-devåæ¯é½å¯ï¼ç¶åè¿å ¥Hutool项ç®ç®å½æ§è¡ï¼
./hutool.sh install
ç¶åå°±å¯ä»¥ä½¿ç¨Mavenå¼å ¥äºã
ðï¸æ·»ç å ç¦
ðåæ¯è¯´æ
Hutoolçæºç å为两个åæ¯ï¼åè½å¦ä¸ï¼
åæ¯ | ä½ç¨ |
---|---|
v5-master | 主åæ¯ï¼releaseçæ¬ä½¿ç¨çåæ¯ï¼ä¸ä¸å¤®åºæ交çjarä¸è´ï¼ä¸æ¥æ¶ä»»ä½præä¿®æ¹ |
v5-dev | å¼ååæ¯ï¼é»è®¤ä¸ºä¸ä¸ªçæ¬çSNAPSHOTçæ¬ï¼æ¥åä¿®æ¹æpr |
ðæä¾bugåé¦æ建议
æ交é®é¢åé¦è¯·è¯´ææ£å¨ä½¿ç¨çJDKçæ¬å¢ãHutoolçæ¬åç¸å ³ä¾èµåºçæ¬ã
ð§¬è´¡ç®ä»£ç çæ¥éª¤
- å¨Giteeæè Githubä¸fork项ç®å°èªå·±çrepo
- æforkè¿å»ç项ç®ä¹å°±æ¯ä½ ç项ç®cloneå°ä½ çæ¬å°
- ä¿®æ¹ä»£ç ï¼è®°å¾ä¸å®è¦ä¿®æ¹v5-devåæ¯ï¼
- commitåpushå°èªå·±çåºï¼v5-devåæ¯ï¼
- ç»å½GiteeæGithubå¨ä½ é¦é¡µå¯ä»¥çå°ä¸ä¸ª pull request æé®ï¼ç¹å»å®ï¼å¡«åä¸äºè¯´æä¿¡æ¯ï¼ç¶åæ交å³å¯ã
- çå¾ ç»´æ¤è å并
ðPRéµç §çåå
Hutool欢è¿ä»»ä½äººä¸ºHutoolæ·»ç å ç¦ï¼è´¡ç®ä»£ç ï¼ä¸è¿ç»´æ¤è æ¯ä¸ä¸ªå¼ºè¿«çæ£è ï¼ä¸ºäºç §é¡¾ç 人ï¼éè¦æ交çprï¼pull requestï¼ç¬¦åä¸äºè§èï¼è§èå¦ä¸ï¼
- 注éå®å¤ï¼å°¤å ¶æ¯ä¸ªæ°å¢çæ¹æ³åºæç §Javaææ¡£è§èæ ææ¹æ³è¯´æãåæ°è¯´æãè¿åå¼è¯´æçä¿¡æ¯ï¼å¿ è¦æ¶è¯·æ·»å åå æµè¯ï¼å¦ææ¿æï¼ä¹å¯ä»¥å ä¸ä½ ç大åã
- Hutoolç缩è¿æç
§Eclipseï¼
ä¸è¦è·æ说IDEAå¤å¥½ç¨ï¼ç»´æ¤è é常æï¼å¦ä¸ä¼ï¼IDEAçé¦ï¼æ¹äºEclipseå¿«æ·é®åèæå¤äºï¼é»è®¤ï¼tabï¼ç¼©è¿ï¼æ以请éµå®ï¼ä¸è¦åæäºæ§ç©ºæ ¼ä¸tabçé®é¢ï¼è¿æ¯ä¸ä¸ªç 人çä¹ æ¯ï¼ã - æ°å çæ¹æ³ä¸è¦ä½¿ç¨ç¬¬ä¸æ¹åºçæ¹æ³ï¼Hutooléµå¾ªæ ä¾èµååï¼é¤éå¨extra模åä¸å æ¹æ³å·¥å ·ï¼ã
- 请pull requestå°
v5-dev
åæ¯ãHutoolå¨5.xçæ¬å使ç¨äºæ°çåæ¯ï¼v5-master
æ¯ä¸»åæ¯ï¼è¡¨ç¤ºå·²ç»åå¸ä¸å¤®åºççæ¬ï¼è¿ä¸ªåæ¯ä¸å 许prï¼ä¹ä¸å 许修æ¹ã - æ们å¦æå ³éäºä½ çissueæprï¼è¯·ä¸è¦è¯§å¼ï¼è¿æ¯æ们ä¿æé®é¢å¤çæ´æ´çä¸ç§æ¹å¼ï¼ä½ ä¾æ§å¯ä»¥ç»§ç»è®¨è®ºï¼å½æ讨论ç»ææ¶æ们ä¼éæ°æå¼ã
ðææ¡£æºç å°å
ææ¡£æºç å°å ç¹å»åå¾æ·»ç å ç¦
âStar Hutool
Top Related Projects
FASTJSON 2.0.x has been released, faster and more secure, recommend you upgrade.
Google core libraries for Java
Apache Commons Lang
Spring Framework
Main Portal page for the Jackson project
Apache Commons IO
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot