基础java复习

本文通过具体示例展示了Java中ArrayList、HashSet及HashMap等集合框架的使用方法,包括元素的添加、迭代显示以及子字符串的获取等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import java.util.*;

class Goover
{
   static String s;

  public static void main(String[] args)
  {
      /*System.out.println("list");
      ArrayList list = new ArrayList();
      list.add("b");
      list.add("a");
      list.add("c");
      //System.out.println(list);
      //System.out.println(list.toArray());
      //System.out.println(list.toString());
       Iterator it = list.iterator();
      while(it.hasNext())
      {
          System.out.println(it.next());
      } 
      System.out.println("set");
      Set s = new HashSet();
      s.add("b");
      s.add("a");
      s.add("c");
       Iterator it1 = s.iterator();
      while(it1.hasNext())
      {
          System.out.println(it1.next());
      } 
       System.out.println("map");
       HashMap hm = new HashMap();
       hm.put("j1","b");
       hm.put("j2","a");
       hm.put("j3","c");
       Set set =hm.entrySet();
       Iterator it2 = set.iterator();
       while(it2.hasNext())
       {
          Map.Entry me = (Map.Entry)it2.next();
          System.out.println("key:"+me.getKey()+"/tvalues:"+me.getValue());
       }
       //
       //char x = 'd';//int x =100, byte x = 100, char x ='d',short x =100;
       //switch(conditionType)conditionType:int,char,short,byte
       long x=100;
       switch(x)
       {
          case 100:
          {
            System.out.println("100");
            break; 
          }
          case 110:
             {
            System.out.println("110");
            break; 
          }
                
       }
      String s = " hello,world";
      System.out.println(s.substring(7,12));
      System.out.println("w-index:"+s.indexOf("w"));
      System.out.println(s.substring(s.indexOf("w"),12));
      System.out.println("s_length:"+s.length());
      System.out.println(s.substring(7,s.length()));
      boolean boo = true;
      if(boo == false)
      {
        System.out.println("a");
      }else
      {
           System.out.println("b");
      }
    
      System.out.println("i="+i);*/
System.out.println(s);
System.out.println(s.charAt(0));

  } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值