Adding to an ArrayList Java

后端 未结 7 1427
终归单人心
终归单人心 2020-11-28 12:24

I am a beginner to java, and need some help.

I am trying to convert an Abstract Data type Foo which is an associated list to an Arraylist of the strings B. How do yo

7条回答
  •  旧时难觅i
    2020-11-28 13:07

    thanks for the help, I've solved my problem :) Here is the code if anyone else needs it :D

    import java.util.*;
    
    public class HelloWorld {
    
    
    public static void main(String[] Args) {
    
    Map> map = new HashMap>();
    List list = new ArrayList();
    list.add(1);
    list.add(9);
    list.add(11);
    map.put(1,list);        
    
        int First = list.get(1);
        int Second = list.get(2);
    
        if (First < Second) {
    
            System.out.println("One or more of your items have been restocked. The current stock is: " + First);
    
            Random rn = new Random();
    int answer = rn.nextInt(99) + 1;
    
    System.out.println("You are buying " + answer + " New stock");
    
    First = First + answer;
    list.set(1, First);
    System.out.println("There are now " + First + " in stock");
    }     
    }  
    }
    

提交回复
热议问题