关于一些JAVA的基础知识总结
2016-08-28 01:02
751 查看
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]
相关文章推荐
- Java基础知识 十七 (关于反射一些方法的总结)
- JAVA基础知识之网络编程——-关于阻塞IO/非阻塞IO/同步IO/异步IO的一些参考文章
- java的一些基础知识总结
- java基础知识,一些概念的区别总结
- java学习笔记,关于java的一些基础知识,适用于初学者,第一节
- 关于java的基础知识总结
- 关于博弈论基础知识的一些总结
- 黑马程序员-------java循环的一些总结(基础知识)
- javaweb_关于Servlet一些基础知识笔记
- java基础知识要点总结之几个重要关键字(关于static、this、final、)
- 关于进行java学习和Android开发,本人认为的一些基础的入门必需知识,全程手敲
- 关于Java基础的一些笔试题总结
- 【JavaScript 基础知识】一篇关于 JavaScript 一些知识点的总结 —— 持续更新
- 关于java基础知识的一些小感悟
- 总结一些java中的基础知识
- 关于JAVA的一些基础知识
- 关于前端基础知识的一些总结
- java的一些基础知识总结
- 关于Java基础的一些笔试题总结
- 关于博弈论基础知识的一些总结