关于一些JAVA的基础知识总结
来源:互联网 发布:python面向对象封装 编辑:程序博客网 时间:2024/05/21 06:27
Java 基础
- 有如下两个数组 int a[] = {1,3,5,7,8}; int b[] = {0,3,5,10,20}; 选出属于数组b但不属于数组a的元素
public class TestInt { public static void main(String[] args) { int a[] = {1,3,5,7,8}; int b[] = {0,3,5,10,20}; System.out.println(Arrays.toString(find(b,a))); } //选出属于数组a但不属于数组b的元素 public static int[] find(int[] a, int[] b){ ArrayList<Integer> list = new ArrayList<Integer>(); for(int i = 0; i < a.length; ++i) { boolean bContained = false; for(int j = 0; j < b.length; ++j) { if (a[i] == b[j]) { bContained = true; break; } } if (!bContained) { list.add(a[i]); } } int res[] = new int[list.size()]; for(int i = 0; i < list.size(); ++i){ res[i] = list.get(i); } return res; }}
- 继承、静态的理解
public class TestStaticExtend { public static void main(String[] args) { A se = new B(); se.print(); }}class A{ static { System.out.println("AAAA"); } public A(){ System.out.println("struc A"); } void print(){ System.out.println("this is class A"); }}class B extends A{ static{ System.out.println("BBBB"); } public B(){ System.out.println("struc B"); } void print(){ System.out.println("this is class B"); }}
结果:
AAAA
BBBB
struc A
struc B
this is class B
- String 的理解
public class TestString { String str = new String("hello world"); String[] strarr = {"hello world"}; char[] ch = { 'a', 'b', 'c' }; static TestString ex = new TestString(); public static void main(String[] args) { change(ex.str, ex.ch); System.out.println(ex.getStr()+ " and " + Arrays.toString(ex.ch)); change(ex.strarr, ex.ch); System.out.println(ex.strarr[0] + " and " + Arrays.toString(ex.ch)); } public static void change(String[] str, char[] ch) { str[0] = "test ok"; ch[0] = 'g'; } public static void change(String str, char[] ch) { ex.setStr("test ok"); ch[0] = 'g'; } public String getStr() { return str; } public void setStr(String str) { this.str = str; }}
结果:
test ok and [g, b, c]
test ok and [g, b, c]
0 0
- 关于一些JAVA的基础知识总结
- 关于一些基础知识的总结
- Java基础知识 十七 (关于反射一些方法的总结)
- 关于JAVA的一些基础知识
- java的一些基础知识总结
- java的一些基础知识总结
- 关于java的基础知识总结
- 关于博弈论基础知识的一些总结
- 关于博弈论基础知识的一些总结
- 关于博弈论基础知识的一些总结
- 关于java的一些基础知识和经验
- 关于java基础知识的一些小感悟
- java基础知识,一些概念的区别总结
- Java的一些基础知识
- 一些java的基础知识
- 一些java的基础知识
- java的一些基础知识
- java的一些基础知识 .
- 【Java】SpringMVC Post&Get编码问题
- sublime text 3的c/c++开发环境搭建
- 5分钟看懂比特币
- CSS3绘制各类图形
- JavaScript与HTML DOM交互
- 关于一些JAVA的基础知识总结
- qt线程同步之信号量
- 四大组件之Activity
- 设计模式之装饰者模式
- 负进制转换
- 指定两个字符串日期相差的天数
- volley源码浅析
- DirectX游戏开发之开发的好伙伴的安装与配置
- 二叉树的构造