728x90


String 


  int length() : 문자열 길이 구함..  필드 length와 혼동주의!

  boolean equals(Object obj) : String 클래스 비교
  boolean equalsIgnoreCase(Object obj) : 대소문자 구문 않고 비교

  String substring(int start) : start부터 끝까지 문자열 발췌 subString으로 혼동주의!
  String substring(int start, int end) : start부터 end 직전까지 문자열 발췌

  String concat(String str) : 문자열 결합
  String replace(char old, char new) : old문자을 new문자로 치환

  String toLowerCase() : 소문자로 변환
  String toUpperCase() : 대문자로 변환

  char charAt(int index) : index번째 문자 반환


class StringTest_1
{
 public  static void main(String args[])
 {
  String s1 = "Hello";
  String s2 = "Good";
  System.out.println(s1.length());
  System.out.println(s1.concat(s2)); // s1과s2를 합침
  
  System.out.println(s1.replace('e','a'));
  
  System.out.println(s1.toLowerCase());
  System.out.println(s2.toUpperCase());
  
  String str1 = new String("이름 홍길동");
  System.out.println(str1);
  System.out.println(str1.replace("홍길동","저팔계"));
 }
}



String 비교
같은 내용의 문자열 상수를 하나의 프로그램 소수에서
두번이상 사용하게 되면 한번만 메모리에 할당하고 이를 공유한다.
String str = "hello";

new String()으로 객체 생성하게되면 별도의 기억 공간을 확보한다.
String str = new String("hello");



class StringTest_2
{
 public static void main( String [] args )
 {
  String s1 = "Good";  // s1과 s2 주소가 같다. 왜냐면 문자열 상수이기 때문에... 메모리 절약 차원에서
  String s2 = "Good";
  
  if(s1 == s2)  
  {
   System.out.println("같다");
  }else
  {
   System.out.println("틀리다");
  }
  
  String s3 = new String("hello");  //s1과 s2 주소가 다르다 왜나면  동적할당 했으므로.
  String s4 = new String("hello");
  
  if(s3 == s4)
  {
   System.out.println("같다");
  }else
  {
   System.out.println("틀리다");
  }
 }// end main

}



class StringTest_3
{
 public static void main( String [] args )
 {
  String s1 = new String("Hello");
  String s2 = new String("Hello");
  
  System.out.println("-String형의 레퍼런스 변수가 참조하는 인스턴스가 같은지 비교-");
  
  if(s1 == s2) // 객체가 가리키는 주소값 비교
  {
   System.out.println("같다");
  }else
  {
   System.out.println("같지않다");
  }
  
  System.out.println("- String형의 데이터값(내용) 비교 -");
  
  if(s1.equals(s2)) //객체에 들어있는 내용 비교,  String 클래스 객체는 객체 자체가 문자열이다.
  {
   System.out.println("같다");
  }else
  {
   System.out.println("같지않다.");
  }
 }// end main
}

728x90

 


자바 모든 클래스는 내부적으로 Object를 상속 받는다.

메서드
  getClass() : 객체의 클래스 이름을 class형으로 반환
  hashCode() : 자바 객체를 식별하는 정수값인 hashcode를 반환
  toString() : 객체의 문자열을 반환

  Object clone() : 객체복사
  boolean equals(Object obj) : 두 객체의 내용이 동일한지 비교할때 사용

  void notify()  :  현제 스레드가 일을 다 했는지 알려준다, 그러면 대기하고 있던 스레드가 수행된다.
  void notifyAll() : 현제 스레드가 일을 다했다는 것을 모두에게 알려준다, 그러면 대기하고 있던 스레드가 수행된다.
  void wait() :  스레드를 기다리게 한다.  

  void finalize() : 객체를 더이상 사용하지 않을때 가비지컬랙션 기능 수행한다. 


class Point
{
 
}

class ObjectTest
{
 public static void main( String [] args )
 {
  System.out.println("-----startPt 객체 정보-----");
  Point startPt = new Point();
  System.out.println("클래스 이름: "+ startPt.getClass());//클래스이름을 구한다.
  System.out.println("해쉬코드 :" + startPt.hashCode());//자바는 객체를 식별하기 위해 해쉬코드를 같는다.
                                                        //해쉬코드는 검색이 용이하다.
  System.out.println("객체 문자열 :"+startPt.toString()); // 객체를 문자열로 반환.
  
  System.out.println();
  System.out.println("------------endPt객체 정보------------");
  Point endPt = new Point();
  System.out.println("클래스 이름: " +endPt.getClass());
  System.out.println("해쉬코드 : " +endPt.hashCode()); //자바 JVM은 hashcode로 객체를 관리함.
  System.out.println("객체 문자열 : "+endPt.toString());
  
 }// end main
}

class Test
{
 public String toString()
 {
  return "오늘은 목요일 입니다";
 }
}
class ObjectTest_2
{
 public static void main( String [] args )
 {
  ObjectTest_2 obj = new ObjectTest_2(); //객체 생성
  System.out.println("클래스이름:" + obj.getClass());
  System.out.println("해시코드:" + obj.hashCode());
  System.out.println("객체문자열:" + obj.toString());
  
  Test test = new Test();
  System.out.println(test.toString());
 }// end main

}


728x90

Properties 클래스는 말그대로 속성을 모아서 하나의 객체로 만들어 제공한다.
이런 클래스가 필요한 이유는 프로그램이 시작되기 전에 여러개의 속성들중 원하는
속성들을 미리 인식하게 하여 전반적인 실행환경을 조율하고 좀더 신속한 처리속도를
가져오는데 목적이 있다.

Method

put("key","value");
getProperty("key"); key에 해당하는 값을 얻는다.
list(printWriter out);  인자로 전달된 출력스트림에 속성 목록을 출력한다.

import java.util.*;
import static java.lang.System.out;

class PropertiesTest
{
 public static void main( String [] args )
 {
  Properties prop = new Properties();
  
  prop.put("user","scott");
  prop.put("pwd","tiger");
  prop.put("driver","oracle.jdbc.driver.OracleDriver");  //오라클 드라이버도 모두 클래스
  
  String user = prop.getProperty("user");
  String pwd = prop.getProperty("pwd");
  String db_driver = prop.getProperty("driver");
  
  out.println("===================keys================");
  
  // 키값들만 얻어 내기
  Enumeration en = prop.propertyNames();
  while(en.hasMoreElements());
  {
   out.println(en.nextElement());
  }
  
  out.println("=============prop.list(System.out)==========");
  prop.list(System.out); //모두 출력
  
 }// end main
 

}


 

728x90

Vector


Constructor

  public Vector()  : default constructor
  public Vector(int initialCapacity)  : initialCapacity로 지정된 공간을 생성
  public VectorIint initialCapacity, int capacityIncrement)    : capacityIncrement 만큼 늘어나게 한다.

Method
  public void addElement(0bject newElement) : 객체를 Vector의 맨 끝에 추가
  public void insertElement(Object newElement, int index) : index위치에 객체를 객체를 삽입
  public void setElement(Object obj,int index) : index번째 값을 Obj로 바꾼다.
  public Object elementAt(int index) : index 번째 요소를 리턴한다.
  public Object firstElement() : 첫번째 요소 접근
  public Object lastElement() : 마지막 요소 접근
  public int size() : Vector 갯수 리턴


import java.util.*;

class VectorTest_1
{
 public static void main( String [] args )
 {
  Vector vec = new Vector();
  
  for(int i = 0 ; i<args.length ; i++)
  {
   vec.addElement(args[i]);  //데이터를 벡터에 삽입
  }
  
  String str;
  
  for(int i = 0; i<vec.size(); i++)
  {
   str = (String)vec.elementAt(i);  //벡터 요소에 접근
   System.out.println(str);
  }
 }// end main
}


import java.util.*;
class VectorTest_2
{
 public static void main( String [] args )
 {
  Vector vec = new Vector();
  
  for(int i = 0 ; i < args.length ; i++)
  {
   vec.addElement(args[i]);
  }
  
  String str = "ccc";
  
  if(vec.contains(str))
  {
   int i  = vec.indexOf(str);
   System.out.println("해당 객체가 "+(i+1)+"번째 있습니다");
  }else
  {
   System.out.println("해당 객체가 없습니다.");
  }
 }// end main
}


import java.util.*;

class VectorTest_3
{
 public static void main( String [] args )
 {
  Vector vec = new Vector();
  for(int i = 0 ;i < args.length; i++)
  {
   vec.addElement(args[i]);
  }
  System.out.println("벡터 size: "+ vec.size());
  System.out.println("백터 capacity :" + vec.capacity()); // 기본이 10
  String str;
  for(int i = 0 ; i < vec.size(); i++)
  {
   str = (String)vec.elementAt(i);
   System.out.println(str);
  }
  
  vec.removeElementAt(2);
  System.out.println("제거한 후");
  System.out.println("벡터 size: "+ vec.size());
  System.out.println("백터 capacity :" + vec.capacity());
  for(int i = 0 ; i < vec.size(); i++)
  {
   str = (String)vec.elementAt(i);
   System.out.println(str);
  }
  
 }// end main

}

import java.util.*;

class VectorTest_4
{
 public static void main(String args[])
 {
  String s1 = "hello1";
  String s2 = "hello2";
  String s3 = "hello3";
  
  Vector vec = new Vector();
  vec.addElement(s1);
  vec.addElement(s2);
  vec.addElement(s3);
  
  for(int i = 0 ; i < vec.size() ; i++)
  {
   System.out.println((String)vec.elementAt(i));
  }
  
  Enumeration e1 = vec.elements(); // 벡터로 부터 요소를 모두 받는다.
  
  while(e1.hasMoreElements())
  {
   System.out.println((String)e1.nextElement());
  }
 }
}



 

+ Recent posts