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