• 字符串转数组工具类


    package com.byd.mes.util;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    /**
     *字符串转数组的工具类
     * 
     * @author  */
    public class ArrayUtil {
    
    	/**
    	 *将字符串转换成一维数组
    	 * 
    	 * @param input
    	 * @param spliter
    	 * @return
    	 */
    	public static String[] strToArray(String input, String spliter) {
    		if (input.indexOf(spliter) < 0) {
    			return new String[] { input };
    		} else {
    			return input.split(spliter);
    		}
    	}
    
    	/**
    	 * 将字符串转成二维数组
    	 * 
    	 * @param input
    	 * @param spliter
    	 * @return
    	 */
    	public static List<Map> strToMapList(String input, String spliter) {
    		List<Map> tempLst = new ArrayList<Map>();
    		if (input.indexOf(spliter) < 0) {
    			return tempLst;
    		} else {
    			String[] temp = input.split(spliter);
    			if (temp.length % 2 != 0) {// 奇数个
    				return tempLst;
    			} else {// 偶数个
    				for (int i = 0; i < temp.length / 2; i++) {
    					Map tempMap = new HashMap();
    					tempMap.put("X", temp[i * 2]);
    					tempMap.put("Y", temp[i * 2 + 1]);
    					tempLst.add(tempMap);
    				}
    				return tempLst;
    			}
    		}
    	}
    
    	public static String strArrToString(String[] arrStrs) {
    		StringBuffer sb = new StringBuffer();
    		String ret = "";
    		for (String str : arrStrs) {
    			sb.append(str + ";");
    		}
    		ret = sb.substring(0, sb.length() - 1);
    		return ret;
    	}
    }
    
  • 相关阅读:
    zzuli oj 1120 最值交换
    zzuli oj 1119 一维数组排序
    zzuli oj 1118 数列有序
    zzuli oj 1117 查找数组元素
    寒假集训 字符串专题 1001
    zzuli oj 1116
    A
    Codeforces Round #615 (Div. 3) E. Obtain a Permutation
    Codeforces Round #615 (Div. 3) F. Three Paths on a Tree
    Codeforces Round #603 (Div. 2)F. Economic Difficulties
  • 原文地址:https://www.cnblogs.com/qq1988627/p/6606895.html
Copyright © 2020-2023  润新知