課程
/云計算&大數據
/大數據
/快速入門Hadoop3.0大數據處理
跟著課程學到很多,對大數據有個系統的了解,寫代碼的時候沒有找到mapUtils 和 DateUtils, 麻煩可以提供下mapUtils 和 DateUtils嗎 ?
2020-02-15
源自:快速入門Hadoop3.0大數據處理
正在回答
DateUtils代碼:
package test.top10;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
?* 日期工具類
?*/
public class DateUtils {
? ? private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
? ? private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
? ? /**
? ? ?* 轉換日期格式
? ? ?* 從yyyyMMdd轉換為yyyy-MM-dd
? ? ?* @param dt
? ? ?* @return
? ? ?*/
? ? public static String transDataFormat(String dt){
? ? ? ? String res = "1970-01-01";
? ? ? ? try {
? ? ? ? ? ? Date date = sdf1.parse(dt);
? ? ? ? ? ? res = sdf2.format(date);
? ? ? ? }catch (Exception e){
? ? ? ? ? ? System.out.println("日期轉換失?。?+dt);
? ? ? ? }
? ? ? ? return res;
? ? }
}
MapUtils代碼:
import java.util.*;
?* Map工具類
public class MapUtils {
? ? ?* 根據Map的value值降序排序
? ? ?* @param map
? ? ?* @param <K>
? ? ?* @param <V>
? ? public static <K, V extends Comparable<? super V>> Map<K, V> sortValue(Map<K, V> map) {
? ? ? ? List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet());
? ? ? ? Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
? ? ? ? ? ? ? ? int compare = (o1.getValue()).compareTo(o2.getValue());
? ? ? ? ? ? ? ? return -compare;
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? Map<K, V> returnMap = new LinkedHashMap<K, V>();
? ? ? ? for (Map.Entry<K, V> entry : list) {
? ? ? ? ? ? returnMap.put(entry.getKey(), entry.getValue());
? ? ? ? return returnMap;
舉報
快速入門Hadoop3.0數據處理,輕松邁入大數據領域
2 回答主播的json數據在哪里可以獲得呢
2 回答這個安裝包在哪里給我呢 官網太慢了下載
1 回答hadoop安裝包在哪?
1 回答導入失敗,失敗的原因會是哪些呢?
3 回答在云服務器上面搭建的話,/etc/hosts文件中ip應該配置內網還是外網呢
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2020-02-18
DateUtils代碼:
package test.top10;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
?* 日期工具類
?*/
public class DateUtils {
? ? private static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");
? ? private static SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd");
? ? /**
? ? ?* 轉換日期格式
? ? ?* 從yyyyMMdd轉換為yyyy-MM-dd
? ? ?* @param dt
? ? ?* @return
? ? ?*/
? ? public static String transDataFormat(String dt){
? ? ? ? String res = "1970-01-01";
? ? ? ? try {
? ? ? ? ? ? Date date = sdf1.parse(dt);
? ? ? ? ? ? res = sdf2.format(date);
? ? ? ? }catch (Exception e){
? ? ? ? ? ? System.out.println("日期轉換失?。?+dt);
? ? ? ? }
? ? ? ? return res;
? ? }
}
2020-02-18
MapUtils代碼:
package test.top10;
import java.util.*;
/**
?* Map工具類
?*/
public class MapUtils {
? ? /**
? ? ?* 根據Map的value值降序排序
? ? ?* @param map
? ? ?* @param <K>
? ? ?* @param <V>
? ? ?* @return
? ? ?*/
? ? public static <K, V extends Comparable<? super V>> Map<K, V> sortValue(Map<K, V> map) {
? ? ? ? List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet());
? ? ? ? Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
? ? ? ? ? ? ? ? int compare = (o1.getValue()).compareTo(o2.getValue());
? ? ? ? ? ? ? ? return -compare;
? ? ? ? ? ? }
? ? ? ? });
? ? ? ? Map<K, V> returnMap = new LinkedHashMap<K, V>();
? ? ? ? for (Map.Entry<K, V> entry : list) {
? ? ? ? ? ? returnMap.put(entry.getKey(), entry.getValue());
? ? ? ? }
? ? ? ? return returnMap;
? ? }
}