473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

how to print first string in a line

hello friends,
can u help me.
how to print first string in a line.(before first space)
for example:
String str={"Hello world java"}

output
Hello
Feb 1 '07 #1
2 2130
hirak1984
316 100+
may be this code will help:
Expand|Select|Wrap|Line Numbers
  1. import java.util.StringTokenizer;
  2. public class A1 {
  3. public static void main(String args[])
  4. {
  5. A2 newA2=new A2();
  6.  int a[]={1,2,3,4,5,6,7,8,9};
  7. int i=a.length;
  8. for(int j=0;j<i;j++)
  9.  newA2.PrintA(a[j]);
  10. String aa=new String("hello world java");
  11. StringTokenizer tokens = new StringTokenizer (aa," ");
  12. System.out.println(tokens.nextElement());
  13. }
  14. }
  15.  

hello friends,
can u help me.
how to print first string in a line.(before first space)
for example:
String str={"Hello world java"}

output
Hello
Feb 1 '07 #2
r035198x
13,262 8TB
may be this code will help:
Expand|Select|Wrap|Line Numbers
  1. import java.util.StringTokenizer;
  2. public class A1 {
  3. public static void main(String args[])
  4. {
  5. A2 newA2=new A2();
  6. int a[]={1,2,3,4,5,6,7,8,9};
  7. int i=a.length;
  8. for(int j=0;j<i;j++)
  9. newA2.PrintA(a[j]);
  10. String aa=new String("hello world java");
  11. StringTokenizer tokens = new StringTokenizer (aa," ");
  12. System.out.println(tokens.nextElement());
  13. }
  14. }
  15.  
It is much prefered these days not to use tokenizer but to use the split method
Expand|Select|Wrap|Line Numbers
  1.  String s = "Hello World"; 
  2. String[] words = s.split(" ");
  3.  
now the array words contains the two strings
Feb 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mmccaws | last post by:
Thanks ahead for your help I'm trying to learn what I can do with echo and print statements. I figured out the echo statement and below is the simple version using print. I've tried two dozen...
12
by: neutrino | last post by:
Greetings to the Python gurus, I have a binary file and wish to see the "raw" content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string...
9
by: François Pinard | last post by:
Hi, people. I hope someone would like to enlighten me. For any application handling Unicode internally, I'm usually careful at properly converting those Unicode strings into 8-bit strings before...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
2
by: CC | last post by:
Hi: I've conjured up the idea of building a hex line editor as a first real Python programming exercise. To begin figuring out how to display a line of data as two-digit hex bytes, I created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.