1、无重复字符的最长子串

输入: "abcabcbb"
输出: 3
解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
class Solution {
public int lengthOfLongestSubstring(String s) {
int max = 0;
int curNoStrIndexStart = 0;
Map<String,Integer> map = new HashMap<>();
for (int i=0;i < s.length();i++) {
String index = String.valueOf(s.charAt(i));
if (map.containsKey(index)) {
curNoStrIndexStart = Math.max(map.get(index),curNoStrIndexStart);
}
max = Math.max(max,i - curNoStrIndexStart +1);
map.put(index,i + 1);
}
return max;
}
}

2、mysql获取表的元数据信息

import java.io.*;
import java.sql.*;
import java.util.*; public class DBEntityInit { private static String propName = "db.properties"; private static Connection connection = null; private static Map<String, List<Column>> tableData = new HashMap<>(); static {
connection = getConnection(propName);
} public static Connection getConnection(String propName){
Connection conn = null;
try {
InputStream in = new FileInputStream(new File(propName));
Properties properties = new Properties();
properties.load(in);
String url = properties.getProperty("jdbc.url");
String username = properties.getProperty("jdbc.username");
String driver = properties.getProperty("jdbc.driver");
String password = properties.getProperty("jdbc.password");
Class.forName(driver);
conn = DriverManager.getConnection(url,username,password);
} catch (SQLException | ClassNotFoundException | IOException e) {
e.printStackTrace();
}
return conn;
} public static void initTableData() {
ResultSet tables = null;
try {
DatabaseMetaData metaData = connection.getMetaData();
tables = metaData.getTables(null, null, null, new String[]{"TABLE"});
while (tables.next()) {
tableData.put(tables.getString(3),new ArrayList<>());
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (tables != null) {
tables.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void initTableColumn(String tableName) {
List<Column> columns = tableData.get(tableName);
PreparedStatement pst = null;
try {
String sql = "select * from " + tableName;
pst = connection.prepareStatement(sql);
ResultSetMetaData metaData = pst.getMetaData();
int columnCount = metaData.getColumnCount();
for (int i=0 ; i < columnCount; i++) {
Column column = new Column();
column.setName(metaData.getColumnName(i+1));
column.setType(metaData.getColumnTypeName(i+1));
columns.add(column);
}
//tableData.put(tableName,columns); } catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (pst != null) {
pst.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static void initComment(String tableName) {
//与数据库的连接
PreparedStatement pst = null;
String tableSql = "select * from" + tableName;
List<String> comments = new ArrayList<>();//列名注释集合
ResultSet rs = null;
List<Column> columns = tableData.get(tableName);
try {
pst = connection.prepareStatement(tableSql);
rs = pst.executeQuery("show full columns from " + tableName);
while (rs.next()) {
String comment = rs.getString("Comment");
comments.add(comment);
} for (int i=0 ;i < columns.size() ;i++) {
Column column = columns.get(i);
column.setComment(comments.get(i));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException e) {
e.printStackTrace();
} }
} public static void closeConnection(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static Map<String, List<Column>> init() {
initTableData();
for (String key : tableData.keySet()) {
initTableColumn(key);
initComment(key);
}
closeConnection(connection);
return tableData;
} public static String getPropName() {
return propName;
} public static void setPropName(String propName) {
DBEntityInit.propName = propName;
} public static void main(String[] args) { init();
for (Map.Entry<String,List<Column>> entry : tableData.entrySet()) {
List<Column> value = entry.getValue();
System.out.println("--------------表名" + entry.getKey());
for (Column column : value) {
System.out.print(column.getName() + "---");
System.out.print(column.getType() + "---");
System.out.print(column.getComment());
System.out.println();
}
} } // public static void initColumnComment(String tableName) {
//
// try {
// List<Column> cList = tableData.get(tableName);
// DatabaseMetaData metaData = connection.getMetaData();
// ResultSet columns = metaData.getColumns(null, null, tableName, "%");
//
// while (columns.next()) {
// Column column = new Column();
// String name = columns.getString("COLUMN_NAME");
// String type = columns.getString("TYPE_NAME");
// String comment = columns.getString("REMARKS");
// column.setName(name);
// column.setType(type);
// column.setComment(comment);
// cList.add(column);
// }
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// } }

相关实体

public class Column {

    private String name;
private String type;
private String comment; public String getName() {
return name;
} public void setName(String name) {
name = name;
} public String getType() {
return type;
} public void setType(String type) {
this.type = type;
} public String getComment() {
return comment;
} public void setComment(String comment) {
this.comment = comment;
}
}

3、日期的加减操作

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date; public class DateCalculate { private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /**
* 获取形如yyyy-MM-dd HH:mm:ss
* @param date
* @return
*/
public static String datetimeToString(Date date) {
return sdf.format(date);
} /**
* 根据时间字符串获取日期
* @param dateString
* @return
* @throws ParseException
*/
public static Date stringToDatetime(String dateString) throws ParseException {
return sdf.parse(dateString);
} /**
* 获取本月最后一天
* @return
*/
public static Date getMonthStartDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_MONTH,1);
return calendar.getTime();
} /**
* 获取本月最后一天
* @return
*/
public static Date getMonthEndDate(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
return calendar.getTime();
} /**
* 获取指定日期所属周的开始时间
* @param date
* @return
*/
public static Date getBeginWeekDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1) {
dayOfWeek += 7;
}
cal.add(Calendar.DATE,2 - dayOfWeek);
return cal.getTime();
} /**
* 距离指定日期所属周结束时间
* @return
*/
public static Date getEndWeekDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1) {
dayOfWeek += 7;
}
cal.add(Calendar.DATE,8 - dayOfWeek);
return cal.getTime();
} /**
* 对指定日期进行年份加减操作
* @param date
* @param num
* @return
*/
public static Date calculateDateOfYear(Date date,Integer num) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR,num);
return calendar.getTime();
} /**
* 对指定日期月份进行加减操作
* @param date
* @param num
* @return
*/
public static Date calculateDateOfMonth(Date date,Integer num) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.MONTH,num);
return calendar.getTime();
} /**
* 对指定日期天数进行加减操作
* @param date
* @param num 负整数 正整数
* @return
*/
public static Date calculateDateOfDay(Date date,Integer num) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH,num);
return calendar.getTime();
} public static void main(String[] args) throws ParseException { System.out.println(datetimeToString(getMonthStartDate(sdf.parse("2019-12-04 12:09:52"))));
System.out.println(datetimeToString(getEndWeekDate(sdf.parse("2019-12-04 12:09:52"))));
System.out.println(datetimeToString(calculateDateOfYear(stringToDatetime("2019-12-04 12:09:52"),-2)));
}
}  

最新文章

  1. ping环回地址和ping主机地址的区别
  2. jquery animate 动画效果使用解析
  3. ng-bind 与ng-model区别
  4. AngularJS 2.0
  5. luogg_java学习_03_流程控制及循环结构
  6. Spring配置数据库固定代码
  7. RHEL7安装配置TigerVNC
  8. jQuery中的.live()与die()
  9. 积累的VC编程小技巧之列表框
  10. .NET Core微服务之基于Ocelot+Butterfly实现分布式追踪
  11. Css样式压缩、美化、净化工具 源代码
  12. 复习-css控制文本字体属性
  13. LyX使用中的一些问题
  14. load() 方法
  15. IE7下面踩得坑
  16. [C#.Net]C#连接Oracle数据库的方法
  17. [NOI 2016]循环之美
  18. Java入门:基础算法之线性搜索
  19. 服务器编程入门(13) Linux套接字设置超时的三种方法
  20. 对极几何(Epipolar Geometry)

热门文章

  1. 个人项目-WC (java实现)
  2. FileZilla_Server:425 Can&#39;t open data connection 问题解决
  3. Activity + 基础UI
  4. Java枚举的用法和原理深入
  5. Nios II IDE代码优化,quartus ii 11.0版本IDE
  6. 搜狐视频 登录 md5 加密破解
  7. SpringBoot中使用Jackson将null值转化为&quot;&quot;或者不返回的配置
  8. python基础语法15 面向对象2 继承,多态,继承json模块中JSONEncoder,并派生出新的功能
  9. 第05组 Beta冲刺(2/4)
  10. Python面向对象 | isinstance和issubclass