1. package demo14;
    2. import java.util.*;
    3. public class l4_0 {
    4. public static void main(String[] args) {
    5. ArrayList <String> myAlist=new ArrayList <String>();
    6. Scanner input=new Scanner(System.in);
    7. String s;
    8. int n=3;
    9. while(true){
    10. s=input.next();
    11. if(s.equals("q")){break;}
    12. myAlist.add(s); }
    13. System.out.println( "线性列表中的值:"+myAlist);
    14. if(n> myAlist.size( )) {
    15. myAlist.add("55555") ; }
    16. else {
    17. myAlist.set(3, "wwe"); }
    18. System.out.println( "修改后的线性列表中的值:"+myAlist);
    19. } }
    1. package demo14;
    2. import java.util.*;
    3. public class l4_1 {
    4. public static void main(String[] args) {
    5. Random r = new Random();
    6. ArrayList<Integer> mylist = new ArrayList<Integer>();
    7. for (int i = 0; i <= 9; i++) {
    8. int x = r.nextInt(30);
    9. mylist.add(x);
    10. }
    11. mylist.add(55555);
    12. System.out.println("初始化可变数组列表为:" + mylist);
    13. // 利用迭代器进行遍历
    14. Iterator it = mylist.iterator();
    15. System.out.println("遍历并修改可变数组列表为:");
    16. while (it.hasNext()) {
    17. System.out.print(":" + (Integer.parseInt(String.valueOf(it.next())) - 20));
    18. }
    19. System.out.println();
    20. it.remove();
    21. System.out.println("初始化可变数组列表为:" + mylist);
    22. }
    23. }
    1. package demo14;
    2. import java.util.*;
    3. public class l5 {
    4. public static void main(String[] args) {
    5. LinkedList <Integer> mylist=new LinkedList<Integer>();
    6. for(int i=1;i<=10;i++){
    7. mylist.add(i);
    8. }
    9. System.out.println(mylist);
    10. mylist.remove(4);
    11. System.out.println(mylist);
    12. }
    13. }
    1. package demo14;
    2. import java.util.*;
    3. public class l6 {
    4. public static void main(String[] args) {
    5. Map<String, String> hm = new HashMap<String, String>();
    6. hm.put("301", "k1");
    7. hm.put("203", "k3");
    8. hm.put("102", "k2");
    9. hm.put("204", "k4");
    10. Set keys = hm.keySet();
    11. Iterator it = keys.iterator();
    12. while (it.hasNext()) {
    13. String x1 = (String) it.next();
    14. String x2 = (String) hm.get(x1);
    15. System.out.println(x1 + " " + x2);
    16. }
    17. System.out.println("_____________");
    18. }
    19. }
    1. package demo14;
    2. import java.util.*;
    3. class goods {
    4. String s1;
    5. int x;
    6. double v;
    7. public goods() {
    8. s1 = "厂家名称";
    9. x = 0;
    10. v = 0;
    11. }
    12. public goods(String name, int x, double v) {
    13. s1 = name;
    14. this.x = x;
    15. this.v = v;
    16. }
    17. }
    18. public class l6_1 {
    19. public static void main(String[] args) {
    20. goods g1, g2, g3;
    21. String s1, s2, s3;
    22. s1 = "011";
    23. s2 = "012";
    24. s3 = "021";
    25. g1 = new goods("海尔冰箱", 400, 3000);
    26. g2 = new goods("美的冰箱", 300, 3000);
    27. g3 = new goods("海尔洗衣机", 200, 2000);
    28. HashMap<String, Object> goodsmap = new HashMap<String, Object>();
    29. goodsmap.put(s1, g1);
    30. goodsmap.put(s2, g2);
    31. goodsmap.put(s3, g3);
    32. Set keys = goodsmap.keySet();
    33. Iterator it = keys.iterator();
    34. while (it.hasNext()) {
    35. String x1 = (String) it.next();
    36. goods gx = (goods) goodsmap.get(x1);
    37. System.out.println(x1 + " " + gx.s1 + " " + gx.x + " " + gx.v + " 总价值:" + gx.x * gx.v);
    38. System.out.println("-------------------------------------");
    39. }
    40. }
    41. }
    1. package demo14;
    2. public class l1 {
    3. public static void main(String[] args) {
    4. //基本类常用形式=将字符串数字转乘数值
    5. String s="123";
    6. int x=Integer.parseInt(s);
    7. System.out.println("输出转换后的整型数"+(x+1));
    8. System.out.println("输出未转换的数据"+(s+1));
    9. //封装整型类对象 =将 数值 转字符串
    10. int x1=123456;
    11. String sx1=String.valueOf(x1);
    12. System.out.println("输出转换后的整型数"+(sx1+11));
    13. }
    14. }
    1. package demo14;
    2. public class l1 {
    3. public static void main(String[] args) {
    4. //基本类常用形式=将字符串数字转乘数值
    5. String s="123";
    6. int x=Integer.parseInt(s);
    7. System.out.println("输出转换后的整型数"+(x+1));
    8. System.out.println("输出未转换的数据"+(s+1));
    9. //封装整型类对象 =将 数值 转字符串
    10. int x1=123456;
    11. String sx1=String.valueOf(x1);
    12. System.out.println("输出转换后的整型数"+(sx1+11));
    13. }
    14. }
    1. package demo14;
    2. public class l1 {
    3. public static void main(String[] args) {
    4. //基本类常用形式=将字符串数字转乘数值
    5. String s="123";
    6. int x=Integer.parseInt(s);
    7. System.out.println("输出转换后的整型数"+(x+1));
    8. System.out.println("输出未转换的数据"+(s+1));
    9. //封装整型类对象 =将 数值 转字符串
    10. int x1=123456;
    11. String sx1=String.valueOf(x1);
    12. System.out.println("输出转换后的整型数"+(sx1+11));
    13. }
    14. }
    1. package demo14;
    2. import java.util.*;
    3. class mystack {
    4. private LinkedList ld = new LinkedList();
    5. public void push(String s) {
    6. ld.addFirst(s);
    7. }
    8. public String pop() {
    9. return String.valueOf(ld.removeLast());
    10. }
    11. public Boolean isEmpty() {
    12. return ld.isEmpty();
    13. }
    14. public void print() {
    15. System.out.println("栈内存储情况:" + ld);
    16. }
    17. }
    18. public class l4 {
    19. public static void main(String[] args) {
    20. Scanner myin = new Scanner(System.in);
    21. mystack stack = new mystack();
    22. System.out.println("输入输入以q结束");
    23. while (true) {
    24. String s = myin.next();
    25. if (s.equals("q")) {
    26. break;
    27. }
    28. stack.push(s);
    29. }
    30. stack.print();
    31. System.out.println("演示先进先出的栈处理");
    32. while (!stack.isEmpty()) {
    33. System.out.print(" " + stack.pop());
    34. }
    35. }
    36. }