AÇIKLAMA
Stringler ve StringBuffer ve diziler üzerinde çeşitli işlemlerin yapıldığı ekleme, silme ve karakterleri teker teker silme gibi özelliklere sahip fonksiyonların kullanımına dair örnek teşkil eder.
Projenin Tamamını Aşağıdaki Linkten İndirebilirsiniz.
Program Kodu:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package deneme;
import javax.swing.*;
/**
*
* @author NEO
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Object objectRef = "hello";
String string = "goodbye";
char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
boolean booleanValue = true;
char characterValue = 'K';
int integerValue = 7;
long longValue = 10000000;
float floatValue = 2.5f; // f suffix indicates that 2.5 is a float
double doubleValue = 33.333;
StringBuffer buffer = new StringBuffer();
buffer.insert( 0, objectRef );
buffer.insert( 0, " " ); // each of these contains two spaces
buffer.insert( 0, string );
buffer.insert( 0, " " );
buffer.insert( 0, charArray );
buffer.insert( 0, " " );
buffer.insert( 0, charArray, 3, 3 );
buffer.insert( 0, " " );
buffer.insert( 0, booleanValue );
buffer.insert( 0, " " );
buffer.insert( 0, characterValue );
buffer.insert( 0, " " );
buffer.insert( 0, integerValue );
buffer.insert( 0, " " );
buffer.insert( 0, longValue );
buffer.insert( 0, " " );
buffer.insert( 0, floatValue );
buffer.insert( 0, " " );
buffer.insert( 0, doubleValue );
String output = "buffer after inserts:\n" + buffer.toString();
buffer.deleteCharAt( 10 ); // delete 5 in 2.5
buffer.delete( 2, 6 ); // delete .333 in 33.333
output += "\n\nbuffer after deletes:\n" + buffer.toString();
JOptionPane.showMessageDialog( null, output,
"StringBuffer insert/delete", JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
// TODO code application logic here
}
}
| Yorumlar |
|
Powered by !JoomlaComment 3.26

