| | |
String to Object
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 23
Reputation:
Solved Threads: 0
Hi, How do i create a class called Text
that creates an object from a string
and that deletes the first word of the text
have no idea
I was starting like
But really i have no idea
Please any help is gratefull
that creates an object from a string
and that deletes the first word of the text
have no idea
I was starting like
Java Syntax (Toggle Plain Text)
public class Text{ public static void main(String[] args) { String str = "this is a little text and i have to delete the first word this "; } }
But really i have no idea
Please any help is gratefull
•
•
Join Date: Apr 2007
Posts: 14
Reputation:
Solved Threads: 4
hi:
you can see my code whether help you
package com.structure;
import java.util.ArrayList;
import java.util.List;
public class Text {
String statement;
List<Character> listchar = new ArrayList<Character>();
public Text(String statement) {
super();
this.statement = statement;
exchangeList();
}
private void exchangeList() {
for (int i = 0; i < statement.length(); i++) {
listchar.add(statement.charAt(i));
}
}
public String deleteIndex(int index) {
String temporary="";
listchar.remove(index);
for (Character c : listchar) {
temporary += c;
}
return statement = temporary;
}
public String getStatement() {
return statement;
}
public void setStatement(String statement) {
this.statement = statement;
}
public static void main(String args[]) {
Text text = new Text("this is deng statement");
System.out.println(text.getStatement());
text.deleteIndex(4);
System.out.println(text.getStatement());
}
}
you can see my code whether help you
package com.structure;
import java.util.ArrayList;
import java.util.List;
public class Text {
String statement;
List<Character> listchar = new ArrayList<Character>();
public Text(String statement) {
super();
this.statement = statement;
exchangeList();
}
private void exchangeList() {
for (int i = 0; i < statement.length(); i++) {
listchar.add(statement.charAt(i));
}
}
public String deleteIndex(int index) {
String temporary="";
listchar.remove(index);
for (Character c : listchar) {
temporary += c;
}
return statement = temporary;
}
public String getStatement() {
return statement;
}
public void setStatement(String statement) {
this.statement = statement;
}
public static void main(String args[]) {
Text text = new Text("this is deng statement");
System.out.println(text.getStatement());
text.deleteIndex(4);
System.out.println(text.getStatement());
}
}
•
•
•
•
Hi, How do i create a class called Text
that creates an object from a string
and that deletes the first word of the text
have no idea
I was starting like
But really i have no ideaJava Syntax (Toggle Plain Text)
public class Text{ public static void main(String[] args) { String str = "this is a little text and i have to delete the first word this "; } }
Please any help is gratefull
Extend existing String class in say MyString.
In MyString's constructor
- take a String as argument.
- Cut out the first word and pass on the rest to base class.
•
•
•
•
hi:
you can see my code whether help you
package com.structure;
import java.util.ArrayList;
import java.util.List;
public class Text {
String statement;
List<Character> listchar = new ArrayList<Character>();
public Text(String statement) {
super();
this.statement = statement;
exchangeList();
}
..................
public static void main(String args[]) {
Text text = new Text("this is deng statement");
System.out.println(text.getStatement());
text.deleteIndex(4);
System.out.println(text.getStatement());
}
}
Are you Agile.. ?
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Change Tab Order
- Next Thread: Executing Shell script from Java code.
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arc arguments array arrays automation binary bluetooth c++ chat class classes client code codesnippet component csv database doctype draw ebook eclipse error event exception fractal freeze game givemetehcodez graphics gui html ide image input integer intellij iphone j2me java java.xls javaprojects jmf jni jpanel julia linux list loop loops mac map method methods mobile netbeans newbie number online oracle page parameter plazmic print problem program programming project recursion reporting rotatetext scanner screen sell server set size sms socket sort sourcelabs sql string superclass swing system template test testautomation threads time title tree tutorial-sample windows working






