小编Sha*_*ram的帖子

Java - ArrayList未检测到重复值

我为我的程序编写了以下类:

public class RefGen {

    private static String refNo;

    protected static void generate(){

         //Create array to store reference
         ArrayList<String> refList = new ArrayList<>();

         //Get date and set output format
         DateFormat dateFormat = new SimpleDateFormat("yyMMdd");        
         Date curDate = new Date();

          //Variables
          String clientKey = InGenUI.clientText.getText();
          String refDate = dateFormat.format(curDate); 
          String refType = InGenUI.typeCombo.getSelectedItem().toString();
          String userName = InGenUI.userCombo.getSelectedItem().toString();
          String ref;
          int n = 1;

          //Create Reference
          refNo = clientKey.toUpperCase() + "/" + refDate + "/" + refType + "/" + userName + …
Run Code Online (Sandbox Code Playgroud)

java arrays contains arraylist

2
推荐指数
1
解决办法
136
查看次数

无法将字符串附加到字典键

我已经编程了不到四个星期,遇到了一个我无法弄清楚的问题.我正在尝试将字符串值附加到现有字符串中,并在其中存储现有字符串,但如果键中已存在任何值,则"str object has no attribute'sadndnd".

我已经尝试将值转换为列表,但这也不起作用.我需要使用.append()属性,因为update只是替换clientKey中的值,而不是附加到已存储的任何值.在做了一些更多的研究之后,我现在明白我需要以某种方式拆分存储在clientKey中的值.

任何帮助将不胜感激.

data = {}

while True:

    clientKey = input().upper()
    refDate = strftime("%Y%m%d%H%M%S", gmtime())
    refDate = refDate[2 : ]
    ref = clientKey + refDate

    if clientKey not in data:
        data[clientKey] = ref

    elif ref in data[clientKey]:
        print("That invoice already exists")

    else:
        data[clientKey].append(ref)

        break
Run Code Online (Sandbox Code Playgroud)

python dictionary key append key-value

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

append ×1

arraylist ×1

arrays ×1

contains ×1

dictionary ×1

java ×1

key ×1

key-value ×1

python ×1